Re: Drop-down box in php

From: Date: Tue, 20 Apr 2004 16:32:00 +0000
Subject: Re: Drop-down box in php
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-33977@lists.php.net to get a copy of this message
From: "andy amol" <andy_amol_2003@yahoo.com> > I would like to know how to create and populate drop down boxes in php. > I want the value to be populated from database. > What I am try to do is to provide the forign key value as combo box option, so that I do not have to check for referential integrity. You still have to check. Just because you provide a discreet number of options in a <select> box doesn't mean that's really all the user can choose from. There are many ways to manipulate the data. That being said, just create a loop as you draw items from your database. <?php echo '<select name="something" size="1">'; $sql = "SELECT name FROM products WHERE ..."; $result = query($sql); while($row = fetch_assoc($result)) { echo "<option value=\"{$row['name']}\">{$row['name']}</option>\n"; } echo "</select>"; I don't know what database you're using, so query() and fetch_assoc() are generic. ---John Holmes...

« previous php.db (#33977) next »