ali_b Posted April 3, 2007 Share Posted April 3, 2007 hey, i have a page on my website that has a drop down menu. it has towns in my area and i have a database that i can make display the data in it in a table on another page. what i want it to do is..... on the drop down menu if i click North berwick i want it to go to a page where it shows all the shops in north berwick which are in the database.. and if i click on gullane it would show all the shops in gullane and so on. Could you please help me on how to do this, Thanks, Ali Link to comment https://forums.phpfreaks.com/topic/45437-displaying-the-right-stuff/ Share on other sites More sharing options...
grimmier Posted April 3, 2007 Share Posted April 3, 2007 I would start with an IF statement at the top of the page, to check for $_POST values, for the drop down. if they are not set, ie this is the first time at the page, then load the page as it currently is. If there is $_POST data, ie they changed the city. run another query and use the results from that in your page display. for the list to be able to post the form and reload the page, you will need to use a little Java. But first you have to setup an onChange() call for your list. Add this inside your Select tag for the list onchange="DoSubmission();" You can put this anywhere in the code. (i prefer to keep it close to the form itself) <script type="text/javascript" language="JavaScript"><!-- function DoSubmission() { document.form1.submit(); } //--></script> Now you just need to make sure your form is set to reload the same page on submit. Link to comment https://forums.phpfreaks.com/topic/45437-displaying-the-right-stuff/#findComment-220642 Share on other sites More sharing options...
joquius Posted April 3, 2007 Share Posted April 3, 2007 Umm... <? // the list $query = mysql_query ("SELECT * FROM `table`"); while ($data = mysql_fetch_array ($query)) { ?><a href="?city=<?=$data['id']?>"><?=$data['name']?>< / a ><? } ?> <? // the page $id = (isset ($_GET['city'])) ? $_GET['city'] : $default; $city = mysql_query ("SELECT * FROM `table` WHERE `id` = '$id'"); ?>html... and if it's a select list; onclick="'window.location='?city=<?=$data['id']?>'" Link to comment https://forums.phpfreaks.com/topic/45437-displaying-the-right-stuff/#findComment-220700 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.