Jump to content

Dropdown list problems...


Seaholme

Recommended Posts

Hey all (again)

I'm back to ask for more assistance with the exact same dropdown list. Yep. I keep discovering new and unsolvable (by myself, anyway!) problems with just one thing, and for some reason nothing else is going wrong for me! I promise I'll stop plaguing this forum with questions at some point!

 

Anyway: the problem is that I have a dropdown list which fetches a list from the database and shows all the entries fitting a particular criterion in that list... however, no matter what entry is selected from the dropdown list, the only one ever sent by the form is always the last entry. So effectively there's no point in having a dropdown list, just the final entry.

 

This is the PHP

// Get all the data from the dogs 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

$dogid = $row['id']; }

echo '<bR><br>Select a dog for a basic checkup<br><form action="basiccheckup.php" method=post> 
<select name=dogid>';
             
// Get all the data from the dogs 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 "<option value=\"$dogid\">{$row['name']}</option>";
}

echo '</select>';

 

Any ideas as to how to solve it? I assume the problem must lie in the form somehow, but I'm not 100%.

Link to comment
https://forums.phpfreaks.com/topic/207390-dropdown-list-problems/
Share on other sites

value=\"$dogid\"

Since $dogid is not in your while loop, it will be the same value for every drop down item you create.

 

I'd suggest setting the $dogid before trying to use it.

 

-cb-

 

PS: There is no reason to use two while loops, that first loop is not doing anything.

Archived

This topic is now archived and is closed to further replies.

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