PHP and drop-down lists

I want to have a simple option box
ex:

<select name="blah_1">
    <option name="option_1" value="option_1" selected="true">
    <option name="option_2" value="option_2" selected="false">
</select>

to have a value automatically selected according to the values in the database.

For example, in the database, if I have a field named “field_1”, and one row has the value of “option_1”, I want “option_1” to be selected. How would I go about doing that?

if u get ur query inside an array:
[php]$result=mysql_query(‘SELECT …’);
$row=fetch_assoc($resulr);[/php]

u may use a function from: http://phphelp.com/forums/viewtopic.php?t=7477 (second post)

[php]$blahs_values=array(
‘option_1’=>‘whatever_may_be_displayed_1’,
‘option_2’=>‘whatever_may_be_displayed_2’
);
echo makeselect (‘blah_1’, $blahs_values, $row[‘field_1’])[/php]

Ok, cool. I check it out. Thanks.

Did it work?

www.ut’

Yep. It worked wonderfully. Thank you.

Sponsor our Newsletter | Privacy Policy | Terms of Service