[SOLVED]MySql data into a radio button

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
iijb
Forum Commoner
Posts: 43
Joined: Wed Nov 26, 2008 11:34 pm

[SOLVED]MySql data into a radio button

Post by iijb »

Hi all

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

Thanks in advance

iijb
Last edited by iijb on Fri May 21, 2010 1:57 am, edited 1 time in total.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: MySql data into a radio button

Post 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:
User avatar
iijb
Forum Commoner
Posts: 43
Joined: Wed Nov 26, 2008 11:34 pm

MySql data into a radio button

Post 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
Post Reply