dthomas31uk Posted October 30, 2008 Share Posted October 30, 2008 Hi. have a page that allows a user to select a country and from that show the cities in that country, but the problem I have is that when I have more than one city for a particular country the country drop down list shows numerous countries of the same country. Its probably better to see what I am on about by giving you a link to the page http://www.gostoke.eu/eu_home.php Here is the code that I have. Hope someone can help. Thanks //@$cat=$_GET['cat']; // Use this line or below line if register_global is off @$cat=$HTTP_GET_VARS['cat']; // Use this line or above line if register_global is off ///////// Getting the data from Mysql table for Pick Up list box////////// $querPick=mysql_query("SELECT city, id FROM uk_place"); if (!$querPick) { exit('<p>Unable to obtain category list from the ' . 'database.</p>'); } ///////////// End of query for first list box//////////// ///////// Getting the data from Mysql table for first list box////////// $quer2=mysql_query("SELECT DISTINCT country,id FROM eu_place order by country"); ///////////// End of query for first list box//////////// /////// for second drop down list we will check if category is selected else we will display all the subcategory///// if(isset($cat) and strlen($cat) > 0){ $quer=mysql_query("SELECT DISTINCT city FROM eu_place where id=$cat order by city"); }else{$quer=mysql_query("SELECT DISTINCT city FROM eu_place order by city"); } ////////// end of query for second subcategory drop down list box /////////////////////////// /// Add your form processing page address to action in above line. Example action=dd-check.php//// ////////// Starting of first drop downlist ///////// print 'Select country destination:'; echo "<select class='countrydrop' name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>"; echo mysql_error(); while($noticia2 = mysql_fetch_array($quer2)) { if($noticia2['id']==@$cat){echo "<option selected value='$noticia2[id]'>$noticia2[country]</option>"."<BR>";} else{echo "<option value='$noticia2[id]'>$noticia2[country]</option>";} } echo "</select>"."<BR>"; ////////////////// This will end the first drop down list /////////// ////////// Starting of second drop downlist ///////// print 'Select city destination:'; echo "<select class='citydrop' name='subcat'><option value=''>Select one</option>"; while($noticia = mysql_fetch_array($quer)) { echo "<option value='$noticia[city]'>$noticia[city]</option>"; } echo "</select>"."<BR>"; Quote Link to comment https://forums.phpfreaks.com/topic/130727-problem-grouping-areas-in-my-database/ Share on other sites More sharing options...
sasa Posted October 30, 2008 Share Posted October 30, 2008 you need separate table for country and cites Quote Link to comment https://forums.phpfreaks.com/topic/130727-problem-grouping-areas-in-my-database/#findComment-678427 Share on other sites More sharing options...
dthomas31uk Posted October 30, 2008 Author Share Posted October 30, 2008 change the table??? Why?? have a dbase called eu_place and in that have country, city... Not sure why. Can you advise Quote Link to comment https://forums.phpfreaks.com/topic/130727-problem-grouping-areas-in-my-database/#findComment-678446 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.