Connecting Tech Pros Worldwide Help | Site Map

MySQL Results into drop down menu

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 12:54 PM
Ian N
Guest
 
Posts: n/a
Default MySQL Results into drop down menu

Hi,

I have a site populates a drop down menu with options, say...

Option 1
Option 2
Option 3
Option 4

If i customer is currently set to Option 3, i'd like this to be at the
top of the Drop down menu and therefore the default option.

This seems like a pretty simple thing but their doesn't seem to be a
quick fix.

Can anyone advise me on how to best deal with this?

Thanks in advance.

Ian

  #2  
Old July 17th, 2005, 12:54 PM
micha
Guest
 
Posts: n/a
Default Re: MySQL Results into drop down menu

when php is populating your options (done by a loop, i figure), you
just need an if statement to print selected="selected" for the default
option, like that:

$default ='option3';

$options[0] = 'option0';
$options[1] = 'option1';
$options[2] = 'option2';
$options[3] = 'option3';

foreach($option as $key => $value)
{
print "<option";
if($value == $default)
{
print " selected=\"selected\"";
}
print ">".$value."</option>
}


micha

  #3  
Old July 17th, 2005, 12:55 PM
Ian N
Guest
 
Posts: n/a
Default Re: MySQL Results into drop down menu

Of course!

Thank you for your help

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.