HOW TO RETRIVE DATABASE VALUE TO RADIOBUTTON.

[b]suppose ,I have following radio buttons.
Red
Green
Black
White

I want to retrieve database value to radio button.I tried above code,but it didn’t give any results.Please help me. :o[/b]

why do you need to fetch data from database to put radio value if they have pre assigned value eg red green black white?

but I want to shows that out of 4,only one radio button is automatically selected with database value.

well you need to

[ol][li]connect to the database [/li]
[li]run a query fetching the radio value from a table[/li]
[li]then fetch the result [php]$row = mysql_fetch_assoc($variable_query_name)[/php][/li]
[li]and finally you can echo something like the following[/li][/ol]

<input type="radio" name="color" value="red" <?php if ($row['color'] == "red"){echo "checked";} ;?>/>Red
<input type="radio" name="color" value="Green" <?php if ($row['color'] == "Green"){echo "checked";} ;?>/>Green
<input type="radio" name="color" value="Black" <?php if ($row['color'] == "Black"){echo "checked";} ;?>/>Black
<input type="radio" name="color" value="White" <?php if ($row['color'] == "white"){echo "checked";} ;?> />White

so what this does is compare the value gotten from the database which $row[‘color’]

Sponsor our Newsletter | Privacy Policy | Terms of Service