What's a convenient method to "check" the appropriate radio button when displaying data pulled from a DB? More specifically, I've got a form that has several radio buttons with multiple selections, but obviously only one can/should be selected based on the value in the DB. The only working method I've come up with so far seems cumbersome to me, hence this post. It looks somewhat as follows:
Code: Select all
//set variables to check appropriate radio buttons
if ($rowїnews] == 1) {
$news_rand = " checked";
}
else {
$news_rand = "";
}
if ($rowїnews] == 2) {
$news_last = "checked";
}
else {
$news_last = "";
}Code: Select all
echo "<td><font class='small'>Display news items:</font></td>";
echo "<td><font class='small'>Random<input type='radio' name='news' value='1'$news_rand> Last Entered<input type='radio' name='news' value='2'$news_last></font></td>";