Code example: PHP second-level linkage menu implementation _ PHP Tutorial

Source: Internet
Author: User
The code example shows the implementation of the PHP level-2 linkage menu. For beginners, the PHP second-level linkage menu code example: scriptlanguageJavaScriptvaronecount; onecount0; subcatnewArray ();? Phpmysql_connect (localhost, charles, c for beginners,

PHP second-level linkage menu code example:

  1. < ScriptLanguage = "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. // Linkage function
  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. < 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. < OptionSelected value = "">Main</Option>
  39. <? Php
  40. $ SQL = "select * from entreprise ";
  41. $ Result = mysql_query ($ SQL );
  42. While ($ res = mysql_fetch_row ($ result )){
  43. ?>
  44. < OptionValue = "<? Php echo $ res [0];?> ">
  45. <? Php echo $ res [1];?> </Option>
  46. <? Php}?>
  47. </Select>
  48. < SelectName = "ctype">
  49. < OptionSelected value = "">Sub</Option>
  50. </Select>
  51. < InputType = "submit" name = "Submit" value = "search">
  52. </Form>

The above code is the specific implementation method of the PHP level-2 linkage menu.


Example code of the PHP second-level linkage menu: script language = JavaScript varonecount; onecount = 0; subcat = new Array ();? Php mysql_connect (localhost, charles, c...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.