Aimless Posted July 29, 2010 Share Posted July 29, 2010 Hi, I'm trying to create a dropdown box that is filled by a mysql column. I found this example, which fills the dropdown box with a list of columns in the database, but I want to fill the drop down box with the content in a column. Any guidance on how to do this would be appreciated. Thank you! Example: $connection = mysql_connect("localhost","username","password"); $fields = mysql_list_fields("database", "table", $connection); $columns = mysql_num_fields($fields); echo "<form action=page_to_post_to.php method=POST><select name=Field>"; for ($i = 0; $i < $columns; $i++) { echo "<option value=$i>"; echo mysql_field_name($fields, $i); } echo "</select></form>"; Quote Link to comment https://forums.phpfreaks.com/topic/209225-mysql-php-dropdown/ Share on other sites More sharing options...
tomtimms Posted July 29, 2010 Share Posted July 29, 2010 You will need to use a while loop from a query to get all the contents from the column. $query = "SELECT value FROM database"; $result = mysql_query($result); echo "<select>"; while ($rows = mysql_fetch_array($result) { echo "<option value='$rows['value']'>$rows['value']</option>"; } echo "</select>" Quote Link to comment https://forums.phpfreaks.com/topic/209225-mysql-php-dropdown/#findComment-1092563 Share on other sites More sharing options...
Aimless Posted July 29, 2010 Author Share Posted July 29, 2010 I can't seem to get that to work, are there any other ways to get this to work? Quote Link to comment https://forums.phpfreaks.com/topic/209225-mysql-php-dropdown/#findComment-1092569 Share on other sites More sharing options...
Jessica Posted July 29, 2010 Share Posted July 29, 2010 I can't seem to get that to work, are there any other ways to get this to work? You know, "it doesn't work" is usually the quickest way to get answers on how to fix it. /sarcasm. Why? Quote Link to comment https://forums.phpfreaks.com/topic/209225-mysql-php-dropdown/#findComment-1092570 Share on other sites More sharing options...
tomtimms Posted July 29, 2010 Share Posted July 29, 2010 Aimless show your complete code. Quote Link to comment https://forums.phpfreaks.com/topic/209225-mysql-php-dropdown/#findComment-1092591 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.