Attempting to set up a drop down menu that is tied to a sql
Posted: Sun Sep 20, 2009 5:15 pm
Attempting to set up a drop down menu that is tied to a sql table. I think I almost have all the components. Just can't figure out how to build the array based on optionid and optionname from my sql query. Want the optionname to show up in the drop down, but once a selection is made, I want the option id to post. Any takers? 
Code: Select all
<?
$optiondropdwnquery = "SELECT optionid, optionname FROM OptionsLib WHERE optiongroupid = 1";
$optionsavailresult = mysql_query($optiondropdwnquery);
$options = array('15'=>'DisplayName1','19'=>'DisplayName2','24'=>'DisplayName3','28'=>'DisplayName4','50'=>'DisplayName5');
$selectedValue = isset($_POST['foodtype']) ? $_POST['foodtype'] : '';
echo '<select name="foodtype">' . "\n";
foreach($options as $key=>$value) {
echo '<option value="' . $key. '" ' . ($key== $selectedValue ? 'selected="selected"' : '') . '>' . $value . '</option>' . "\n";
}
echo '</select>';
?>