I have an editable form that includes a dropdown menu. I want the value that was previously selected to be highlighted upon editing the form.
I'm using the following code, which works for the other dropdowns on my form, but not for this one. I've checked, double-checked, and triple-checked the table names, field names, and syntax, and I just flat out don't understand what's wrong with the code.
As an example, here's the basic structure of the tables I'm querying:
Color_Menu
ID Name Item
1 Red Hat
2 Blue Hat
3 Green Shirt
4 Yellow Pants
5 Pink Shirt
User_Menu
ID User FavColor
1 Bob Red
2 Ben Blue
3 Ken Blue
4 Max Red
5 Sam Yellow
Here's the code I'm trying to use:
<?
$result = mysql_query('SELECT FavColor FROM User_Menu WHERE ID = ' . $_GET['ID'])
or exit(mysql_error());
$colorX = $row['FavColor'];
$result = mysql_query('SELECT Color FROM Color_Menu ORDER BY Color')
or exit(mysql_error());
echo "<select name=\"colors\" class=\"selects\">";
while ($row = mysql_fetch_assoc($result)) {
$colorY = $row['Color'];
?>
<option value="<? echo "$colorY"; ?>" <? if (!(strcmp($colorY, "$colorX"))) {echo "SELECTED";} ?>><? echo "$colorY"; ?>
<?
}
echo "</select>";
?>