I have a dropdown box which is populated from a mysql table.
When viewing the box, the order of the options is the same as in the table e.g. a,b,c,d
I have a variable, and would like the dropdown box to be preset to that variable.
FOr example, if the variable was C, the dropdown box would automatically have C selected. The user could then change it if they wanted to.
This is the code for the dropdown box.
<select name ='action'>
<?php
$query = "SELECT action FROM actions";
$result = mysql_query($query);
while($myrow = mysql_fetch_array($result)) {
$action = $myrow['action'];
echo "<option value='$action'>$action</option>\n";
}
?>
</select>
I have tried adding this line above the query....
echo "<option value='$variable'>$variable</option>\n";
...however this just adds the variable as an option to the top of the list. e.g. the list a,b,c,d and when I add the above line with the variable set to B, the dropdown displays b,a,b,c,d.
Could anyone tell me how to properly preset the displayed option? Thank you