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