I frequently work with forms where menus are pulled from a database. When a user enters data in the form and then saves it, if it is retrieved later, the form shows the saved data, including the drop-down menus. The way I normally do this in php is to first retrieve the data for the saved from. Then I create the menus and within the loop of creating the menus I simply add the word "selected" into the results row which equals the saved option on the form.
In other words, within the results loop I'll have something like:
$options .= <option value=$option_id $selected>$option_description</option>";
and the $selected value will be determined by a preceding statement like:
If ($option_id == $saved_id)
{ $selected = "selected";} else {$selected = "";}
The problem I'm facing now is that I am working with a form that returns multiple rows of results. (kind of like have multiple forms on one page) Each row has 4 drop-down menus. So I can't create the menus after returning the results rows because the menus have to appear within the rows. I tried running the menu creation queries within the results rows, but this drastically slows things down. (if I have 12 rows of results, this means that the 4 drop down menus have to be created 12 times each)
I'm just curious if others have dealt with this issue and what solution can be suggested. Thanks!