【发布时间】:2016-07-21 14:04:23
【问题描述】:
我的复选框是使用 while 循环创建的,所以我不能将 id 或名称放在每个人身上,所以我不能更改记录。如果值是1,复选框被勾选,如果我的表中的值为0,则不勾选,这有利于检查,但我不能用它们来更改对应于复选框的记录值吗? 这是我的代码:
<?php
if($records === FALSE) {
die(mysql_error());
}
while($student=mysql_fetch_assoc($records)){
echo "<tr>";
echo "<td>".$student['SID']."</td>";
echo "<td>".$student['Student_Name']."</td>";
if($student['Month_1'] == 1){
echo "<td>"."<input type='checkbox' checked='true'>"."</td>";
}else{
echo "<td>"."<input type='checkbox' checked='false'>"."</td>";
}
if($student['Month_2'] == 1){
echo "<td>"."<input type='checkbox' checked='true'>"."</td>";
}else{
echo "<td>"."<input type='checkbox' checked='false'>"."</td>";
}
if($student['Month_3'] == 1){
echo "<td>"."<input type='checkbox' checked='true'>"."</td>";
}else{
echo "<td>"."<input type='checkbox' checked='false'>"."</td>";
}
if($student['Month_4'] == 1){
echo "<td>"."<input type='checkbox' checked='true'>"."</td>";
}else{
echo "<td>"."<input type='checkbox' checked='false'>"."</td>";
}
if($student['Month_5'] == 1){
echo "<td>"."<input type='checkbox' checked='true'>"."</td>";
}else{
echo "<td>"."<input type='checkbox' checked='false'>"."</td>";
}
if($student['Month_6'] == 1){
echo "<td>"."<input type='checkbox' checked='true'>"."</td>";
}else{
echo "<td>"."<input type='checkbox' checked='false'>"."</td>";
}
if($student['Month_7'] == 1){
echo "<td>"."<input type='checkbox' checked='true'>"."</td>";
}else{
echo "<td>"."<input type='checkbox' checked='false'>"."</td>";
}
if($student['Month_8'] == 1){
echo "<td>"."<input type='checkbox' checked='true'>"."</td>";
}else{
echo "<td>"."<input type='checkbox' checked='false'>"."</td>";
}
if($student['Month_9'] == 1){
echo "<td>"."<input type='checkbox' checked='true'>"."</td>";
}else{
echo "<td>"."<input type='checkbox' checked='false'>"."</td>";
}
if($student['Month_10'] == 1){
echo "<td>"."<input type='checkbox' checked='true'>"."</td>";
}else{
echo "<td>"."<input type='checkbox' checked='false'>"."</td>";
}
if($student['Month_11'] == 1){
echo "<td>"."<input type='checkbox' checked='true'>"."</td>";
}else{
echo "<td>"."<input type='checkbox' checked='false'>"."</td>";
}
if($student['Month_12'] == 1){
echo "<td>"."<input type='checkbox' checked='true'>"."</td>";
}else{
echo "<td>"."<input type='checkbox' checked='false'>"."</td>";
}
echo "</tr>";
}
?>
【问题讨论】:
-
好吧,首先,您的复选框中没有一个具有
name属性,因此如果/当该表单被提交时,则无需提交任何内容。他们也没有value属性,所以即使他们有名字,也没有数据可以连同名字一起提交,所以没有办法将任何特定的复选框与那些高重复性的Month_X位中的任何一个相关联你正在测试。