Seaholme Posted July 7, 2010 Share Posted July 7, 2010 Hey guys, I'm trying to populate a multi dropdown list from a database where it finds all of the dogs (bit of a silly topic, I know, but whatever!) belonging to a certain owner and lists them all in a dropdown list. All I can seem to manage is this, which displays every single dog listed under the owner name, but it gives every single one their own dropdown list, of which they are the sole occupant. I really want them all to just sit in the same dropdown list. Can anybody help me work out how to do it? I've included the PHP below that I'm using currently... although, as I said, it doesn't work! // Get all the data from table $result = mysql_query("SELECT * FROM dogs WHERE owner=".$_SESSION['id']) or die(mysql_error()); while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo '<form action=rader.php method=post> Name: <select name=name> <option value="$row[\'id\']">'; echo $row['id']; echo $row['name']; echo '</option></select><br><br></form>'; ?> Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/207042-populating-a-multiple-dropdown-list/ Share on other sites More sharing options...
msaz87 Posted July 7, 2010 Share Posted July 7, 2010 Only leave the <option></option> bit in the DB loop... // Get all the data from table $result = mysql_query("SELECT * FROM dogs WHERE owner=".$_SESSION['id']) or die(mysql_error()); echo '<form action=rader.php method=post> Name: <select name=name>'; while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo '<option value="$row[\'id\']">'; echo $row['id']; echo $row['name']; echo '</option>'; } echo '</select></form>'; ?> Link to comment https://forums.phpfreaks.com/topic/207042-populating-a-multiple-dropdown-list/#findComment-1082669 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.