大家好,我要实现三级菜单连动的,但是需要javascrpt和php(Mysql)联合使用的将用php语句查出来的数据库表中的字段值赋值给javascript变量。有一问题就是php和javascript的执行先后问题,就是说php是在服务器端执行的,而javascript是在客户端执行的,所以,在他们相互调用的过程中,很多变量的值丢失了。刚刚接触php和javascript,所以说的也不知道对不对,大家见谅,希望大家能够帮助我。以下是我写的错误的程序,看看大家有没有什么思路?
<!--//
var formNames = new Array("formA","formB","formC","formD");
var optionsName = new Array();
var optionsValue = new Array();
var optionsFactor = new Array();
var optionsType = new Array();
<?php
$strSQL = 'select address_state from ' . TABLE_DELIVERY_ADDRESS . ' group by address_state ';
$result = $db->Execute( $strSQL );
$i=0;
while ( !$result->EOF ) {
//$synchronized_str= "area[$count_country] = new Array();\n area[$count_country][0] =".$record_set[1].";\n ";
$synchronized_str= "optionsFactor[$i]=0;\n optionsType[$i]=0;\n optionsName[$i]=optionsValue[$i]=".$result->fields['address_state'].";\n ";
echo $synchronized_str;
$result->MoveNext();
$i=$i+1;
}
for($j=0;$j<=$i;$j++)
{ $state="optionsName[$j]";
//$strSQL= "select address_city from ".TABLE_DELIVERY_ADDRESS." where address_state like %". $state."% group by address_city ";
$strSQL = 'select `address_city` from `'. TABLE_DELIVERY_ADDRESS . '` where `address_state` like "%' . $state .'%" group by `address_city`;';
$result= $db->Execute($strSQL);
while ( !$result->EOF ) {
$synchronized_str="optionsFactor[$i]=".$j."; \n"."optionsType[$i]=1;\n optionsName[$i]=optionsValue[$i]=".$result->fields['address_city'].";\n";
echo $synchronized_str;
$result->MoveNext();
$i=$i+1;
}
}
for($j;$j<=$i;$j++)
{
$city= "optionsName[$j]";
//$strSQL= "select address_town from ".TABLE_DELIVERY_ADDRESS." where address_city like %". $city ."% group by address_town ";
$strSQL = 'select `address_town` from `' . TABLE_DELIVERY_ADDRESS . '` where `address_city` like "%' . $city .'%" group by `address_town` ;';
$result= $db->Execute( $strSQL );
while ( !$result->EOF ) {
$synchronized_str="optionsFactor[$i]=".$j."; \n"."optionsType[$i]=2;\n optionsName[$i]=optionsValue[$i]=".$result->fields['address_town'].";\n";
echo $synchronized_str;
$result->MoveNext();
$i=$i+1;
}
}
for($j;$j<=$i;$j++)
{
$town="optionsName[$j]";
// $strSQL= "select address_area from ".TABLE_DELIVERY_ADDRESS." where address_town like %". $town."% group by address_area ";
$strSQL = 'select `address_area` from `' . TABLE_DELIVERY_ADDRESS . '` where `address_area` IS NOT NULL and `address_town` like "%' . $town .'%" group by `address_area` ;';
$result= $db->Execute( $strSQL );
while ( !$result->EOF ) {
$synchronized_str="optionsFactor[$i]=".$j."; \n"."optionsType[$i]=3;\n optionsName[$i]=optionsValue[$i]=".$result->fields['address_area'].";\n";
echo $synchronized_str;
$result->MoveNext();
$i=$i+1;
}
}
?>