Populating a select form input tag with mysql data

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
dickey
Forum Commoner
Posts: 50
Joined: Thu May 16, 2002 8:04 pm
Location: Sydney, Australia

Populating a select form input tag with mysql data

Post by dickey »

How do I populate a select (drop list) on a form using data from a single column from a mysql table, so that each row in the column becomes an option in the select (drop list).

Any assistance will be greatly appreciated
DSM
Forum Contributor
Posts: 101
Joined: Thu May 02, 2002 11:51 am
Location: New Mexico, USA

Post by DSM »

Code: Select all

<select name = "select">
<?
$sql = mysql_query("SELECT  * FROM table");
while($result = mysql_fetch_array($sql)):
$info = $result&#1111;"info"];
echo"<option value = "$info">$info</option>";
endwhile;
?>
</select>
Hope this helps
Post Reply