MySQL Forums
Forum List  »  PHP

Creating a Dynamic dropdown menu from MYSQL db
Posted by: Richard Mullins
Date: February 18, 2006 10:03AM

Hi All,

Just need a bit of help creating a dynamic dropdown menu that gets two pieces of data. I have a 'student' table within my mysql database with 'ID' and 'Name' values for each student. The code for the dropdown menu is written below but I keep getting errors:

<script language="php">
$query = "SELECT S_ID, Name FROM student ";
$result = mysql_query($query, $mysql_link);
if(mysql_num_rows($result)) {
while($row = mysql_fetch_row($result))
{
print("<option value=\"$row[0]\">$row[0]</option>");
}
} else {
print("<option value=\"\">No students created yet</option>");
}
</script>

I would appreciate it anyone can tell me how I can get both the student ID and Name to appear in a drop down box. So for each student I would like to see the following seperated by a comma:

K888443, Richard Mullins

Thanks for your help in advance,
Rich



Edited 1 time(s). Last edit at 02/18/2006 10:05AM by Richard Mullins.

Options: ReplyQuote


Subject
Written By
Posted
Creating a Dynamic dropdown menu from MYSQL db
February 18, 2006 10:03AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.