Can someone tell me how to populate a drop down menu using a select statement.
Thanks
Populating Drop Down Menus with Select Statement
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
I have this piece of code:
When I test, it gives me the following errors:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\Apache2\htdocs\metering\core.php on line 14
This works
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Apache2\htdocs\metering\core.php on line 16
Can anyone find the problem ? There is data in the database.
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");
}
}
?>Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\Apache2\htdocs\metering\core.php on line 14
This works
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Apache2\htdocs\metering\core.php on line 16
Can anyone find the problem ? There is data in the database.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Where does $connection come from? Also it's a good idea to add error handling to mysql_query() calls:
Mac
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());
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK