我现在有三个下拉:A,B,C
我想要的是:
当我在A里选择了数据时,就根据A里的value的值这个作为条件,查询数据库并在B里显示,C里同上。
数据结构:
ID    ParentsID     classname
1         0           ffsd
2         1           fasf
3         2           fasffd
45        1          fasffd
46        2           fasffd
98        1           fasffd
ParentsID为其上一级类的ID  ParentsID=0为第一类

解决方案 »

  1.   

    拜托别什么都要现成的好不!实现方式:
    1.ajax无刷新获取数据2.页面加载时后台程序向页面写入javascript数据数组,一般用于数据量小的!
      

  2.   

    搜下 php 三级联动菜单  有很多的实例
      

  3.   

    ajax可以实现。
    不会就把所有都读出来,用display none 来显示。
      

  4.   

    请大家帮忙看下这个三级联动哪有错误?
    代码: <script>
       var subcat = new Array();
       <?
       $i=0;
       require("../include/Conn.php");
       $strss="select * from proclasstree where ParentsID!=0";
       $rst=mysql_query($strss,$link);
       while($arr=mysql_fetch_array($rst))
       {
       echo"subcat[".$i++."]=new Array('".$arr["ParentsID"]."','".$arr["ID"]."','".$arr["ClassName"]."');\n";
       //echo "subcat[".$i++."] = new Array('".$arr["dept_id"]."','".$arr["class"]."','".$arr["class_id"]."');\n";
       }
       ?>
        var subcat2 = new Array();
       <?
       $i=0;
       require("../include/Conn.php");
       $strsss="select * from proclasstree where ParentsID!=0";
       $rsts=mysql_query($strsss,$link);
       while($arrs=mysql_fetch_array($rsts))
       {
       echo"subcat2[".$i++."]=new Array('".$arrs["ParentsID"]."','".$arrs["ID"]."','".$arrs["ClassName"]."');\n";
       //echo "subcat[".$i++."] = new Array('".$arr["dept_id"]."','".$arr["class"]."','".$arr["class_id"]."');\n";
       }
       
       ?>
       function changeselect1(locationid)
                {
                 document.myform.ClassList_2.length = 0;
                 document.myform.ClassList_2.options[0] = new Option('请选择','');
                 for (i=0; i<subcat.length; i++)
                  {
                    if (subcat[i][0] == locationid)
                     {
                      document.myform.ClassList_2.options[document.myform.ClassList_2.length] = new Option(subcat[i][1], subcat[i][2]);
                     }
                  }
                }
               function changeselect2(locationid)
                {
                 document.myform.ClassList_3.length = 0;
                 document.myform.ClassList_3.options[0] = new Option('33请选择33','');
                  for (i=0; i<subcat2.length; i++)
                   {
                    if (subcat2[i][0] == locationid)
                    {
                    document.myform.ClassList_3.options[document.myform.ClassList_3.length] = new Option(subcat2[i][2], subcat2[i][1]);
                    }
                   }
                 }
               </script>
      <select name="ClassList_1" id="ClassList_1" style="width:250px; margin:2px 0;" onchange="changeselect1(this.value)">
                  <option value="">请选择</option>
      <?php
      require("../include/Conn.php");
      $rs="select * from proclasstree where ParentsID=0";
      $res=mysql_query($rs,$link);
      $nu=mysql_num_rows($res);
      for($i=0;$i<$nu;$i++)
      {
      $rw=mysql_fetch_array($res);
      echo"<option value='".$rw["ID"]."'>".$rw["ClassName"]."</option>";
      }
      ?>
               </select><br/> 
    <select name="ClassList_2" id="ClassList_2" style="width:250px; margin:2px 0;" onchange="changeselect2(this.value)">
    <option value="">请选择</option>
             
    </select>
    <br/>
    <select name="ClassList_3" id="ClassList_3" style="width:250px; margin:2px 0;">
    <option value="">请选择</option>
    </select>
      

  5.   

    你包那么多次conn.php干嘛,一次就够了