I’m trying to get an already populated dropdown menu to change focus on it’s selection once I do a _REQUEST for an ID from another page – the ID will correlate to the ID of the item in the database.
So here’s the request
$product_id_request=$_REQUEST["product_id"];
and the drop down menu code:
$dropdown_sql="SELECT product_id, product_name, unit_price, unit_quantity, in_stock FROM products";
$dropdown_result=mysql_query($dropdown_sql);
$options="";
while ($row=mysql_fetch_array($dropdown_result)) {
$id=$row["product_id"];
$product_name=$row["product_name"];
$unit_price=$row["unit_price"];
$unit_quantity=$row["unit_quantity"];
$in_stock=$row["in_stock"];
$options.="<OPTION VALUE=\"$id\">$product_name - $unit_quantity";
}
?>
And the dropdown
<OPTION VALUE=0>Select a food
<?php echo $options ?>
</SELECT>
In your while() loop, set the
selectedattribute on yourOPTIONtag. Something like this:You should also close the option tag.
To check for the presence of the ID, edit the top, like this:
The default value will be 0 if it is not supplied.