Seaholme Posted July 11, 2010 Share Posted July 11, 2010 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%. Quote Link to comment https://forums.phpfreaks.com/topic/207390-dropdown-list-problems/ Share on other sites More sharing options...
ChemicalBliss Posted July 11, 2010 Share Posted July 11, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/207390-dropdown-list-problems/#findComment-1084276 Share on other sites More sharing options...
Seaholme Posted July 11, 2010 Author Share Posted July 11, 2010 Thankyou thankyou thankyou thankyou! Working now Quote Link to comment https://forums.phpfreaks.com/topic/207390-dropdown-list-problems/#findComment-1084382 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.