Jump to content

Default selected value in dropdown


mckeegan375

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/222527-default-selected-value-in-dropdown/
Share on other sites

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.