Home > Backend Development > PHP Tutorial > Code example shows the implementation of PHP secondary linkage menu_PHP tutorial

Code example shows the implementation of PHP secondary linkage menu_PHP tutorial

WBOY
Release: 2016-07-15 13:34:27
Original
1182 people have browsed it

For beginners,

PHP secondary linkage menu code example:

  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="< ?php echo $res[0]; ?>">
  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...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template