Hello, all: I need some help with a dynamically populated dropdown menu...
I have managed to dynamically populate the dropdown menu from my item_categories table, and it works fine, EXCEPT once I have entered an item and want to bring it back into the form to UPDATE it, how do I make it so the category for the item is remembered and automatically appears as "selected"
Basically there are 2 tables:
the "item_category" table that hold the list of categories with their respective ID's, like this:
category_id category_name
1 art
2 clothing
3 misc
and second "item" table that hold the products, and is related to the "item_category" table thru the category ID's like this:
item_id title category
109 painting 1
110 drawing 1
111 hat 2
So, as you see in the 'select" form drop down menu script below, the categories are pulled from the 'item_categorty" table just fine, BUT how do I make it so when I bring up, let's say, item #111 the right category appears already as selected???
Appreciate any help!!
thanks!
<SELECT name="category" id="category"> <?php
$query=("select * from item_category order by category_name, category_name desc");
$result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() );
while($row=mysql_fetch_array($result)){
echo "<OPTION VALUE=".$row['category_name'].">".$row['category_name']."</OPTION>";
}
?>
</SELECT>