Ryflex Posted October 1, 2010 Share Posted October 1, 2010 Hi all, Does anyone know if it's possible to generate a dropdown list filled with database information. I use the following to get the information from the database: $query = "SELECT Name FROM city WHERE member_ID = '$member_ID'"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { echo $row['Name'] . '<br>'; } Thnx Ryflex Quote Link to comment https://forums.phpfreaks.com/topic/214934-dropdown-generated-from-database-information/ Share on other sites More sharing options...
ngreenwood6 Posted October 1, 2010 Share Posted October 1, 2010 You are doing it now pretty much just forgetting to add the dropdown... try this: <?php $query = "SELECT NameFROM city WHERE member_ID = '$member_ID'"; $result = mysql_query($query) or die(mysql_error()); echo '<select name="dropdown">'; while($row = mysql_fetch_assoc($result)){ echo '<option>'.$row['Name'] . '</option><br>'; } echo '</select>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/214934-dropdown-generated-from-database-information/#findComment-1118078 Share on other sites More sharing options...
Ryflex Posted October 1, 2010 Author Share Posted October 1, 2010 @ngreenwood6 Thnx works perfectly now Ryflex Quote Link to comment https://forums.phpfreaks.com/topic/214934-dropdown-generated-from-database-information/#findComment-1118085 Share on other sites More sharing options...
Ryflex Posted October 2, 2010 Author Share Posted October 2, 2010 Hi all, A little addition to my question... Is it possible to make the dropdown menu in a way that when I click one of the entries it automaticaly uses that value as a submit. So if I click value 2 the page reloads and $_post the value 2. Thnx Ryflex Quote Link to comment https://forums.phpfreaks.com/topic/214934-dropdown-generated-from-database-information/#findComment-1118360 Share on other sites More sharing options...
ngreenwood6 Posted October 2, 2010 Share Posted October 2, 2010 that is actually a javascript question but I will answer that as well. on your select tag you need to add an onchange event handler. so it would look something like this: <select onchange="this.form.submit();"> Quote Link to comment https://forums.phpfreaks.com/topic/214934-dropdown-generated-from-database-information/#findComment-1118422 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.