Forum Moderators: coopster
I have a form with radio boxes - when I display the form I read the data from a database and put it in the appropriate input boxes - but I have not figured out a way to populate the radio boxes (or dropdowns) - for example if the database says the person is female I would like the radio box for female checked.
I am using MySQL/PHP
Thanks for you help.
Pat
$db_gender = [i]whatever db syntax you use here[/i]; $radio_inputs = ''; $radio = array('Male', 'Female'); foreach ($radio as $gender) {
$checked = ($db_gender == $gender)? ' checked="checked"' : '';
$radio_inputs .= '<input type="radio" name="gender" value="'.$gender.'"' . $checked . ' />';
} print $radio_inputs;