Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading a list/menu button

Status
Not open for further replies.

itechC

Programmer
Feb 13, 2003
71
CA
Hi all,

I need to load a list button from a table in mysql database that i have. The table consists of 14000 cities which i need to put in a drop down list. Does anyone have any ideas...i need to pull this off asap. Thanks in advance.Tek-tips rules.
 
I doubt that putting 14000 cities in a drop down menu will be a good idea in terms of usability. It is also wasting bandwith since probably 13999 items are not the right ones.
Can't you first select by state, county or even the first letter of the city?
The populating of the listbox itself is trivial.
 
I'm populating the cities with whatever the user enters for the state drop down. For example if the choose new york then i will populate cities with all the cities from new york.Any ideas on how to do this???
 
1. Let's say state drop down variable is "state" and the form is posted:
Code:
$SQL = "SELECT * FROM cities WHERE state='".$_POST['state'].'"';
$result = mysql_query($SQL) OR die("Query error: ".mysql_error());
# Print the opening for the <select> element
echo '<select name="city">';
# loop through result set
while ($row = mysql_fetch_assoc($result)){
   # produce HTML output here
   echo '<option>'.$row['city'].'</option>'."\n";
}
echo '</select>';

That's the basic idea.
Assumptions:
-> table is called cities
-> in the cities table column "city" for the name
Haven't you populated your state drop down the same way? Or do I not understand your question correctly?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top