wwfc_barmy_army Posted November 5, 2006 Share Posted November 5, 2006 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 More sharing options...
trq Posted November 5, 2006 Share Posted November 5, 2006 If you know how to retrieve your data, you'd simply loop through the results...[code=php:0]// connect and query databaseecho "<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. Link to comment https://forums.phpfreaks.com/topic/26256-records-in-a-drop-down-box/#findComment-120090 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.