Php simple implementation of second-level linkage, php Linkage

Source: Internet
Author: User

Php simple implementation of second-level linkage, php Linkage

<Script type = "text/javascript"> // jump to function jump () {location. href = '? Firstid = '+ document. getElementById ('first'). value ;}</script> <? Php // connect to the Database @ mysql_connect ('localhost', 'root', ''); mysql_select_db ('test'); mysql_query ('set names utf8 '); $ firstid = isset ($ _ GET ['firstid'])? $ _ GET ['firstid']: ''; // obtain the submitted firstid?> <! -- Obtain Level 1 --> <select id = 'first' onchange = 'dump () '> <option value = ""> --- select --- </option> <? Php $ SQL = 'select * from shoplist where parentid = 0'; $ rs = mysql_query ($ SQL); while ($ rows = mysql_fetch_assoc ($ rs):?> <Option value = "<? Php echo $ rows ['id']?> "<? Php echo $ rows ['id'] = $ firstid? 'Selected': ''?> <? Php echo $ rows ['name']?> </Option> <? Phpendwhile;?> </Select> <! -- Obtain Level 2 --> <select id = 'second'> <option value = ""> --- select --- </option> <? Php $ SQL = "select * from shoplist where parentid = $ firstid"; $ rs = mysql_query ($ SQL); while ($ rows = mysql_fetch_assoc ($ rs):?> <Option value = "<? Php echo $ rows ['id']?> "> <? Php echo $ rows ['name']?> </Option> <? Php endwhile;?> </Select>

Result

 

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.