基于 PHP/MySQL 创建单选按钮集
默认情况下检查按钮有问题:它看起来像:
编码:
$first = TRUE;
if (mysql_num_rows($result))
{
for ($j = 0; $j < mysql_num_rows($result); $j++)
{
$currentCat = mysql_result($result, $j, 'category');
if ($first == TRUE)
{
$first = FALSE;
echo "<input type='radio' name='createCat' value='$currentCat' checked='checked' />$currentCat checked";
}
else
{
echo "<input type='radio' name='createCat' value='$currentCat' />$currentCat ";
echo "non";
}
}
echo <<<_END
<br /><input type='submit' value='Create' /> $error
</form>
_END;
}
注意第一个框没有被选中 HTML 中的输出:
<input type='radio' name='createCat' value='opt1' checked='checked' />opt1 checked<input type='radio' name='createCat' value='opt2' />opt2 non<input type='radio' name='createCat' value='Accounts' />Accounts non <br /><input type='submit' value='Create' />