Jump to content

Recommended Posts

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

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>';

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.