Page 1 of 1

PHP and HTML drop down menus

Posted: Tue Mar 25, 2003 12:13 am
by ee99ee
How do I make the contents of drop down menus dynamic?

What I mean is I want users to be able to add a product to inventory, and it show up in the order form's drop down menu box for selection. I'm not sure how to pull this from the database and have it show up a new entry when a new item is entered into inventory.

Anyone know how I could do this? Let's say the table that has all the inventory is inventory, and the feild that has the contents of the drop down box is called sizes.

-ee99ee

Drop down menu

Posted: Tue Mar 25, 2003 1:49 am
by ups216
if you mean you want a drop list in a form.

You can do this.

1. create a table to record your inventroy
------------------
ID | Name
------------------
1 Book
2 computer
-----------------

2. in the form page. You just select all rows from this table and make up a drop down list.

<?php
$q="select * from inventroy";
$dis="<select name=\"inventory\" size=\"1\">\n";
while( $r=mysql_fetch_array( mysql_query( $q ) ){
$dis.="<option value=\".$r['ID']."\">".$r['Name']."</option>\n";
}
$dis.="</select>";
?>

you can just use
<?=$dis?>
to have a drop down list whose options are coming from inventory table.