mckeegan375 Posted December 23, 2010 Share Posted December 23, 2010 Hi I have been trying to get a value to be selected in a mysql populated dropdown list but can't get it to work and was hoping someone could help I have a database with user info in it and this is an update page where they can update their details. The code i have (which doesn't work) is: <select name="agency"> <? $query1 = mysql_query("SELECT * FROM agents ORDER BY agent ASC",$connect); while($myrow = mysql_fetch_assoc($query1)){ $agent = $myrow['agent']; echo "<option"; if ($agent == $agency) { echo "selected='selected'"; } echo ">$agent</option>"; } ?> </select> The $agency value is the current agency which is stored in the users profile and the value does exist in the list which is being populated (also, i have define $agency further up in my code) so i don't know why the selected value won't display. No value is displayed in the dropdown list on the page - but the values are in the list if i remove the selected='selected' part of the code. Any help yould be greatly appreciated. Merry Christmas Andy Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted December 23, 2010 Share Posted December 23, 2010 you probably need to add space before the selected echo " selected='selected'"; Look at your HTML and you'll probably see no space before selected, invalidating the HTML Quote Link to comment Share on other sites More sharing options...
mckeegan375 Posted December 23, 2010 Author Share Posted December 23, 2010 Wow! fast response and perfect solution! Many thanks! Quote Link to comment 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.