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
Share on other sites

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.