Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display a drop-down menu whose content from database

Status
Not open for further replies.

aas1611

Programmer
Dec 14, 2001
184
DE
Hi,

I have this drop-down menu, a list of authors. The name of the authors are in a database, I want to display it automatically, instead of writing the authors' names one by one.

The code I have written here does not work (which I thought should work), and I dont' know what else I can do:
Code:
echo "<tr><td>Author</td><td><select name=author size=1>";
$result = mysql_query("SELECT Name FROM Authors");
while ($rw = mysql_fetch($result)) {
   echo "<option>".$rw['Name'];
}
echo "</select></td></tr>";
With this code, the drop-down menu come up empty. It IS connected to the database, in case you were wondering :)

Can anybody appoint where I screw up? Thanks!

Andre
 
Code:
echo "<tr><td>Author</td><td><select name=\"author\" size=\"1\">";
$result = mysql_query("SELECT `Name` FROM Authors") or die(mysql_error());
while ($rw = mysql_fetch_assoc($result)) {
   echo "<option value=\"{$rw['Name']}\">{$rw['Name']}</option>";
}
echo "</select></td></tr>";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top