msasan1367 Posted July 20, 2012 Share Posted July 20, 2012 Hi I write this code now I want connect 2 list box to each other and when I select an option in first link box, just show its related data in second please help me thanks <!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Select Cities</title> </head> <body> <table> <tr> <td colspan="2">Religion</TD> <td> <select name="items"> <option value="">Choose province</option> <? $conn=mysql_connect("127.0.0.1", "university", "123456") ; mysql_select_db("university",$conn) or die ("error cannot connect"); $sql = "SELECT * FROM province"; $result = mysql_query($sql,$conn) or die(mysql_error()); while ($array = mysql_fetch_array($result)) { $itemName = $array['provincename']; $itemcode = $array['provinceno']; ?> <option value="<?php print($itemcode); ?>"><?=$itemName?> <? $sqlt = "SELECT * FROM city LEFT JOIN province ON city.provinceno = province.provinceno WHERE `province`.`provinceno` = `city`.`provinceno` AND city.provinceno='$itemcode'; "; ?> <? } ?> </select> </td> </tr> <tr> <td> <select name="items2"> <option value="">Choose city</option> <? $resultt = mysql_query($sqlt,$conn) or die(mysql_error()); while ($array = mysql_fetch_array($resultt)) { $itemNamet = $array['cityname']; $itemci = $array['provinceno']; ?> <option value="<?php print($itemci); ?>"><?=$itemNamet?> <? } ?> </select> </td></tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/265997-relation-two-listbox/ Share on other sites More sharing options...
Barand Posted July 20, 2012 Share Posted July 20, 2012 You could have a look at the baaSelect link below in my sig. Quote Link to comment https://forums.phpfreaks.com/topic/265997-relation-two-listbox/#findComment-1363044 Share on other sites More sharing options...
msasan1367 Posted July 20, 2012 Author Share Posted July 20, 2012 You could have a look at the baaSelect link below in my sig. But I want load data from database in two link box thanks Quote Link to comment https://forums.phpfreaks.com/topic/265997-relation-two-listbox/#findComment-1363112 Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 Barand's solution is the correct one. This is more of a client-side problem than a PHP one. Quote Link to comment https://forums.phpfreaks.com/topic/265997-relation-two-listbox/#findComment-1363113 Share on other sites More sharing options...
msasan1367 Posted July 20, 2012 Author Share Posted July 20, 2012 Barand's solution is the correct one. This is more of a client-side problem than a PHP one. but I have to read data from database, let me describe more in database: I have two tables name "province" & "city" in "province table": proviceno, provincename in "city table": proviceno, cityno, cityname now I have two list box: first list box link to province table in my database, when I click on one of data in list box, second list box show data from city table in database that its proviceno equals to provinceno in "province table" what should I do? please help me Quote Link to comment https://forums.phpfreaks.com/topic/265997-relation-two-listbox/#findComment-1363118 Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 We understand what you're trying to do. Since you haven't attempted it, and don't want to use a pre-made script, we're not sure how to help you besides providing you with the solution you need, or writing you a personal tutorial. Quote Link to comment https://forums.phpfreaks.com/topic/265997-relation-two-listbox/#findComment-1363123 Share on other sites More sharing options...
msasan1367 Posted July 20, 2012 Author Share Posted July 20, 2012 We understand what you're trying to do. Since you haven't attempted it, and don't want to use a pre-made script, we're not sure how to help you besides providing you with the solution you need, or writing you a personal tutorial. I write code at first topic but the problem is: when I choose a province in first list box at second list box city doesnt change to its relative data Quote Link to comment https://forums.phpfreaks.com/topic/265997-relation-two-listbox/#findComment-1363133 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.