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.
Populating Drop Down List/Menu Form
Moderator: General Moderators
Thanks. The tutorial you suggested seems like it was geared toward using javascript and it does not involving the use of MYSQL to dynamically create the menu.
While reading it, I thought that I might be able to create the one query and then break up the $results into separate arrays using php. Then I would not have to query the database three times. I could query it once, then break it up into three arrays that could be sorted individually. Would this be more efficient than three queries?
Thanks,
While reading it, I thought that I might be able to create the one query and then break up the $results into separate arrays using php. Then I would not have to query the database three times. I could query it once, then break it up into three arrays that could be sorted individually. Would this be more efficient than three queries?
Thanks,