Hello all,
How do you make pulldown menus, where the source for the options is a table in a database?
I'll explain in more detail what I'm looking for. In HTML the code is:
<select name="hobby">
<option>Music
<option>Reading
<option>Underwater basket weaving
</select>
Instead of having to write all the options, I want to pull them on the fly from a table containing all the hobbies, especially as this table is growing all the time due to input from the users.
How is this done?
Thanks in advance,
Jerome Smith
How do you make pulldown menus?
Moderator: General Moderators
Here's how I do it
This is how I did it for an application I was using. Modified it a little since you don't care which option may be selected or not when the page is rendered:
Code: Select all
<SELECT NAME="btype" STYLE="border: 1px solid black">
<?php
$sql = "SELECT id, lkupval FROM db_lookups ORDER BY lkupval";
if (!$result = mysql_query($sql, $db))
die("Error retrieving data from projects table");
while ($prow = mysql_fetch_array($result)) {
echo "<OPTION VALUE="".$prow['id']."">".$prow['lkupval']."</OPTION>\n";
}
?>
</SELECT>