我有一个表单,我已经添加了一些复选框,但复选框继续迭代。
这是通过从“学生”表中读取数据生成的表单。然后,它会显示为每个学生的表单,每个学生都有多个复选框。我希望用户为每个学生选择合适的复选框并保存表单。然后将这些数据POST并保存到数据库中。
我的表格部分是:
echo '<td><a href="photos16\\'.$row['SURNAME'].", ".$row['FIRST_NAME'].'.jpg" target="_blank"><img src="photos16\\'.$row['SURNAME'].", ".$row['FIRST_NAME'].'.jpg" height="60"></td></a>';
echo '<td class="combname"><input style="border:none" readonly type="text" name="comb_name[]" value="  '.$row['FIRST_NAME']." ".$row['SURNAME'].'" /></td>';
echo "<td><input style='border:none' readonly type='hidden' name='first_name[]' value='".$row['FIRST_NAME']."' /></td>";
echo "<td><input style='border:none' readonly type='hidden' name='surname[]' value='".$row['SURNAME']."' /></td>";
echo "<td><input style='border:none' readonly type='text' name='stkey[]' value='".$row['STKEY']."' /></td>";
echo "<td><input type='hidden' name='check1[]' value='' /></td>";
echo "<td>Check1<input type='checkbox' name='check1[]' value='1'/></td>";
echo "<td><input type='hidden' name='check2[]' value='' /></td>";
echo "<td>Check2<input type='checkbox' name='check2[]' value='2' /></td>";
echo "<td><input type='hidden' name='check3[]' value='' /></td>";
echo "<td>Check3<input type='checkbox' name='check3[]' value='3' /></td>";
echo "<td>Other: <input type='text' size='15' id='violation' name='violation[]' value='' /></td>";
echo "<td><input type='hidden' name='gender[]' value='".$row['GENDER']."' /></td>";
echo "<td><input type='hidden' name='year[]' value='".$row['SCHOOL_YEAR']."' /></td>";
echo "<td><input type='hidden' name='rollgroup[]' value='".$row['ROLL_GROUP']."' /></td>";
echo "<td><input type='hidden' name='house[]' value='".$row['HOUSE']."' /></td>";
echo "<td><input type='hidden' name='user[]' value=$user /></td>";
echo "</tr>";
复选框周围的数组输出:
[check1] => Array ( [0] => [1] => 1 [2] => [3] => [4] => 1 [5] => [6] => [7] => [8] => [9] => [10] => [11] => [12] => [13] => [14] => [15] => [16] => ) [check2] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => [11] => [12] => [13] => [14] => ) [check3] => Array ( [0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => [11] => [12] => [13] => [14] => )
哪个大多是正确的,但check1应该是[1] =&gt; 1和[3] =&gt; 1而是1和4而我无法解决原因。