Jump to content

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.

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.