PHP and HTML drop down menus

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ee99ee
Forum Newbie
Posts: 9
Joined: Mon Mar 03, 2003 6:45 pm
Location: TN, USA
Contact:

PHP and HTML drop down menus

Post 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
ups216
Forum Newbie
Posts: 3
Joined: Thu Mar 20, 2003 8:00 pm
Location: Sydney
Contact:

Drop down menu

Post 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.
Post Reply