好吧,我已经按照 PHP 代码生成了一个带有单选按钮的表格,这样用户就可以在每一行中只选择一个单选按钮。但是要在每一行中只选择一个单选按钮,它必须是每一行中的唯一名称,对吗?但我不知道如何在 while 循环中设置唯一名称。你们能给我任何想法或解决方案吗?
php代码:
$action = htmlspecialchars($_SERVER['PHP_SELF'])."?class=$class_from";
echo "<form method='post' action='$action' name='attendence'/>";
echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>";
echo "<tr>";
echo "<td class='tdhead' valign='top' width='200'><b>Student Name</b></td>";
echo "<td class='tdhead' valign='top' width='250'><b>Roll No</b>
</td>";
echo "<td class='tdhead' valign='top' width='250'><b>Class Name</b>
</td>";
echo "<td class='tdhead' valign='top' width='200'><b>Present / Not present</b>
</td>";
echo "<td class='tdhead' valign='top' width='200'>Check All <input type= 'checkbox'
onclick='checkAll(this)' /></td>";
echo "</tr>";
while($res2 = mysql_fetch_array($sql2))
{
$sname = inputvalid($res2['sname']);
$roll = inputvalid($res2['roll']);
$class = inputvalid($res2['class']);
echo "<tr>";
echo "<td class='tdhead2' valign='top'>$sname</td>";
echo "<td class='tdhead2' valign='top'>$roll</td>";
echo "<td class='tdhead2' valign='top'>$class</td>";
echo "<td class='tdhead2' valign='top'>
<input type='radio' name='ch[]' value='1' /> <input type='radio' name='ch[]'
value='1' />
</td>";
echo "<td class='tdhead2' valign='top'> </td>";
echo "</tr>";
}
echo "<tr>";
echo "<td class='tdhead2'> </td>";
echo "<td class='tdhead2'> </td>";
echo "<td class='tdhead2'> </td>";
echo "<td class='tdhead2'> </td>";
echo "<td class='tdhead2'><input type='submit' value='Record' name='Submit'
class='submit' /></td>";
echo "</tr>";
echo "</table>";
echo "</form>";
谢谢你的帮助。
更新:
echo "<td class='tdhead2' valign='top'>";
echo '<input type="radio" name="ch'.$counter++.'[]" value="1">';
echo " ";
echo '<input type="radio" name="ch'.$counter.'[]" value="0">';
echo "</td>";