希望这篇文章中给出的PHP二级联动菜单代码示例能够帮助大家提高实际编程能力,增加自己的知识库,巩固已掌握的知识。

对于初学者来说,PHP语言的掌握还是需要在具体实践中不断的去积累经验来增加我们对PHP的理解程度。下面就以一个范例为大家介绍PHP二级联动菜单的实现方法。#t#

代码示例展现PHP二级联动菜单的实现(php二级联动下拉列表)  PHP二级联动菜单 第1张

PHP二级联动菜单代码示例:

  1. <scriptlanguage="JavaScript">
  2. varonecount;
  3. onecount=0;
  4. subcat=newArray();
  5. <?php
  6. mysql_connect("localhost","charles",
    "charles");
  7. mysql_select_db("_crm");
  8. $sql="select*fromsite";
  9. $result=mysql_query($sql);
  10. $count=0;
  11. while($res=mysql_fetch_row($result)){
  12. ?>
  13. subcat[<?phpecho$count?>]=newArray
    ("
    <?phpecho$res[0]?>","<?phpecho
    $res[2]
    ?>","<?phpecho$res[1]?>");
  14. <?php
  15. $count++;
  16. }
  17. echo"onecount=$count;";
  18. ?>
  19. //联动函数
  20. functionchangelocation(locationid)
  21. {
  22. document.myform.ctype.length=0;
  23. varlocationidlocationid=locationid;
  24. vari;
  25. for(i=0;i<onecount;i++)
  26. {
  27. if(subcat[i][2]==locationid)
  28. {
  29. //varnewnewOption1=newOption(subcat[i]
    [1],subcat[i][0]);
  30. //document.all.ctype.add(newOption1);
  31. document.myform.ctype.options[document.
    myform.ctype.length]=newOption(subcat
    [i][1],subcat[i][0]);
  32. }
  33. }
  34. }
  35. </script>
  36. <formmethod="post"name="myform"
    action="ru_query.php">
  37. <selectname="type"onChange="changelocation(
    document.myform.type.options[document.myfo
    rm.type.selectedIndex].value)"
    size="1">
  38. <optionselectedvalue="">main</option>
  39. <?php
  40. $sql="select*fromentreprise";
  41. $result=mysql_query($sql);
  42. while($res=mysql_fetch_row($result)){
  43. ?>
  44. <optionvalue="<?phpecho$res[0];?>">
  45. <?phpecho$res[1];?></option>
  46. <?php}?>
  47. </select>
  48. <selectname="ctype">
  49. <optionselectedvalue="">sub</option>
  50. </select>
  51. <inputtype="submit"name="Submit"value="search">
  52. </form>

以上代码就是PHP二级联动菜单的具体实现方法。

转载请说明出处
知优网 » 代码示例展现PHP二级联动菜单的实现(php二级联动下拉列表)

发表评论

您需要后才能发表评论