php读出mysql中的数据 之后再用js
比如我的表的结构是:
id sname scode stown
1   辽宁   0      0
2   沈阳   1      0
3   黄姑区 1      2
id为编号  sname为地名 scode是省的编号 stown是城市的编号
我该怎么写呢?
谢谢 能不能给一个源码?

解决方案 »

  1.   

    可以这么做的.3个表.分别存取省,城市,地名.通过字段关联.
    JS里运用这样的函数,通过控制相应的stown_ctrl_id的display属性实现.
    function get_stown(scode_num){
            var scodeid = form1.stown.value 
    select_cur = "stown_" + scodeid for (i=0;i<=scode_num;i++){
    tempselect = "stown_ctrl_" + i;
    document.getElementById(tempselect).style.display="none";
    }
    document.getElementById(select_cur).style.display = "";
    }
    选择联动用这个函数生成 $stown
    function mkselect($arritem,$hadselected,$arry,$scode,$scode_num,$display){
    $x = "\n\n<select name=\"stown_$scode\" style=\"DISPLAY:$display\" id=stown_ctrl_$scode_num>";
    for($i=0;$i<count($arritem);$i++){
    if($hadselected ==  $arry[$i]){
    $x .= "\n<option selected value='$arry[$i]'>".$arritem[$i]."</option>" ;
    }else{
    $x .= "\n<option value='$arry[$i]'>".$arritem[$i]."</option>"  ;
    }
    }
    $x .= "</select>";
        return $x ;
    }