By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,409 Members | 1,604 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,409 IT Pros & Developers. It's quick & easy.

MySQL Results into drop down menu

P: n/a

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.

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a
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>

Jul 17 '05 #2

P: n/a
Of course!

Thank you for your help

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.