Populating Drop Down List/Menu Form
Posted: Sun Jan 22, 2006 10:02 pm
I am trying to populate my drop down form fields using PHP and MYSQL. I have search for insight into this issue and have yet found a specific answer to it.
First is this a good idea? It seems like the most efficient and accurate way to create the menu. As I add news records, I will not have to worry about changing the fields.
Basically, I have three form fields. Country, State, City. I then use the results of a query to populate all three each drop down menu. One for Country, one for State, one for City. My problem is that I need to sort each $row[0], $row[1], $row[2] so that the menus are in alphabetical order, but they only sort by one of the three categories. So Country may be in order, but not City or State.
I have been able to create three queries for each category ($result_country, $result_state, $result_city) within the same database connection and then create each form field based on each query using a while loop.
Is this the correct way to do it or is there a php function that I can use to sort the array based on a certain row? Then when I specify it to print from $row[2] I can then sort by that row and for the others sort by their respective row.
Using three separate queries seemed inefficient. It works fine, but once I have a lot of traffic it may not be as efficient.
Any insight would be appreciated.
Thanks.
First is this a good idea? It seems like the most efficient and accurate way to create the menu. As I add news records, I will not have to worry about changing the fields.
Basically, I have three form fields. Country, State, City. I then use the results of a query to populate all three each drop down menu. One for Country, one for State, one for City. My problem is that I need to sort each $row[0], $row[1], $row[2] so that the menus are in alphabetical order, but they only sort by one of the three categories. So Country may be in order, but not City or State.
I have been able to create three queries for each category ($result_country, $result_state, $result_city) within the same database connection and then create each form field based on each query using a while loop.
Is this the correct way to do it or is there a php function that I can use to sort the array based on a certain row? Then when I specify it to print from $row[2] I can then sort by that row and for the others sort by their respective row.
Using three separate queries seemed inefficient. It works fine, but once I have a lot of traffic it may not be as efficient.
Any insight would be appreciated.
Thanks.