Page 1 of 1

[SOLVED]MySql data into a radio button

Posted: Sat May 15, 2010 8:00 pm
by iijb
Hi all

How to show a radio button checked with value from the database.

Thanks in advance

iijb

Re: MySql data into a radio button

Posted: Sat May 15, 2010 9:28 pm
by Jonah Bron
Something along these lines...

Code: Select all

<input type="radio" name="aradiobutton" value="value1"<?php echo ($db_column == 'value1') ? ' checked=""'; ?> />
<input type="radio" name="aradiobutton" value="value2"<?php echo ($db_column == 'value2') ? ' checked=""'; ?> />
<input type="radio" name="aradiobutton" value="value3"<?php echo ($db_column == 'value3') ? ' checked=""'; ?> />
<!-- etc. etc. -->
By the way, PHP questions belong in the PHP Code forum :arrow:

MySql data into a radio button

Posted: Mon May 17, 2010 7:14 am
by iijb
Thanx Jonah Bron,

This line of code worked for me

Code: Select all

<input type="radio" name="aradiobutton" value="value1" <?php if($db_column == value1') echo 'checked="checked"'; ?> />
Regards
iijb