Heim  >  Artikel  >  Backend-Entwicklung  >  代码示例展现PHP二级联动菜单的实现_PHP教程

代码示例展现PHP二级联动菜单的实现_PHP教程

WBOY
WBOYOriginal
2016-07-15 13:34:271123Durchsuche

对于初学者来说,

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

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

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


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/445993.htmlTechArticle对于初学者来说, PHP二级联动菜单代码示例: script language = JavaScript varonecount; onecount = 0 ; subcat = new Array(); ?php mysql_connect(localhost,charles, c...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn