Jump to content

Problem grouping areas in my database


dthomas31uk

Recommended Posts

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>";

Link to comment
https://forums.phpfreaks.com/topic/130727-problem-grouping-areas-in-my-database/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.