Problem grouping areas in my database
Posted: Thu Oct 30, 2008 8:26 am
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
Here is the code that I have. Hope someone can help. Thanks
Code: Select all
//@$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>";