Jump to content

Records in a drop down box?


wwfc_barmy_army

Recommended Posts

Hello.

I hope this is the right section to post this in.

I need to get records from a field (name) in a table (artist) and put them in a dropdown box. The dropdown box would then need to output the id (artist_id) for the one that is selected. Can anyone advise me on how to do this?

Thanks.
Link to comment
https://forums.phpfreaks.com/topic/26256-records-in-a-drop-down-box/
Share on other sites

If you know how to retrieve your data, you'd simply loop through the results...

[code=php:0]
// connect and query database

echo "<select name='artists'>";
while ($row = mysql_fetch_assoc($result)) {
  echo "  <option value='{$row['id']}'>{$row['name']}</option>";
}
echo "</select>";
[/code]

Otherwise, you'd best read up on the use of [url=http://php.net/mysql_connect]mysql_connect[/url], [url=http://php.net/mysql_select_db]mysql_select_db[/url], and [url=http://php.net/mysql_query]mysql_query[/url] first.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.