Populating Drop Down Menus with Select Statement
Posted: Wed Oct 29, 2003 3:30 am
Can someone tell me how to populate a drop down menu using a select statement.
Thanks
Thanks
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?
$selectstatement = "SELECT Category_ID, Category_Type FROM category";
$selectresult = mysql_query($selectstatement, $connection);
print "This works";
while ($row = mysql_fetch_array($selectresult)) {
$Category_Type = $row['Category_Type'];
$id = $row['Category_ID'];
if ($id == 1) {
print("<option SELECTED value="$id">$Category_Type</option>\n");
} else {
print("<option value="$id">$Category_Type</option>\n");
}
}
?>Code: Select all
$selectresult = mysql_query($selectstatement, $connection) or die(mysql_error().'<p>'.$selectstatement.'</p>');Code: Select all
<?
$connection = mysql_connect($DBHOST,$DBUSER)
or die("Connection unsuccessful: " . mysql_error());
mysql_select_db($DBASE)
or die("Connection to database unsuccessful: " . mysql_error());
?>