Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.