<form name="reg" id="reg" method="post" action="<?php echo $editFormAction; ?>">
<table width="100%" border="0" align="center" cellpadding="4" cellspacing="4" style="text-align:left;">
<tbody>
<tr>
<th width="117" height="39" bgcolor="#FFE1CC">Student RollNo</th>
<th bgcolor="#FFE1CC">Student Name</th>
<th width="100" bgcolor="#ECFAFF">Old Status</th>
<th width="1" bgcolor="#FFE1CC">Present</th>
<th width="1" bgcolor="#FFE1CC">Absent</th>
<th width="1" bgcolor="#FFE1CC">Leave</th>
<th width="1" bgcolor="#FFE1CC">Holiday</th>
</tr>
<?php
while ($students = mysql_fetch_array($result)) {
?>
<tr>
<td bgcolor="#EAFAFF" class="table1"><?php $id = $students['memberid']; ?><?php echo $_POST['department']; ?>-<?php echo $students['rollno']; ?></td>
<td bgcolor="#EAFAFF" class="table1"><?php echo $students['fullname']; ?></td>
<td align="center" bgcolor="#ECFAFF" class="table1"><?php echo $students['current']; ?></td>
<td width="1" align="center" bgcolor="#FFE2D5" id="present"><input type="radio" name="present[<?php echo $students['memberid']; ?>]" value="Present" /></td>
<td width="1" align="center" bgcolor="#FFE2D5" id="absent"><input type="radio" name="present[<?php echo $students['memberid']; ?>]" value="Absent" /></td>
<td width="1" align="center" bgcolor="#FFE2D5" id="leave"><input type="radio" name="present[<?php echo $students['memberid']; ?>]" value="Leave" /></td>
<td width="1" align="center" bgcolor="#FFE2D5" id="holiday"><input type="radio" name="present[<?php echo $students['memberid']; ?>]" value="Holiday" /></td>
</tr>
<input name="fullname" type="hidden" value="<?php echo $students['fullname']; ?>">
<input name="rollno" type="hidden" value="<?php echo $students['rollno']; ?>">
<input name="percent" type="hidden" value="<?php echo $students['percent']; ?>">
<input name="department" type="hidden" value="<?php echo $_REQUEST['department']; ?>">
<input name="semester" type="hidden" value="<?php echo $_REQUEST['semester']; ?>">
<input name="session" type="hidden" value="<?php echo $_REQUEST['sessionfrom']; ?>-<?php echo $_REQUEST['sessionto']; ?>">
<input name="subject" type="hidden" value="<?php echo $_REQUEST['subject']; ?>">
<input name="date" type="hidden" value="<?php echo date("m-d-Y"); ?>">
<?php
}
?>
<tr>
<td colspan="6" style="vertical-align:middle; text-align: center;"><br />
<input id="Submit" type="submit" name="Submit" value="Submit" style="text-align: center; background-color: #000000; color: #ffffff; border: 1px #000000 solid;" /></td>
<td> </td>
</tr>
</tbody>
</table>
<input type="hidden" name="MM_insert" value="reg" />
</form>
<?php
if (($_POST["MM_insert"] == "reg")){
foreach($_POST['present'] as $student_id => $value) {
$sql = "UPDATE members SET current = '".$value."' WHERE memberid = '".$student_id."' ";
$result = mysql_query($sql);
$sql1 = "INSERT INTO student_attendance (department, semester, session, subject, current, percent, date) VALUES ('".$_REQUEST['department']."','".$_REQUEST['semester']."','".$_REQUEST['session']."','".$_REQUEST['subject']."','$value','".$_REQUEST['percent']."','".$_REQUEST['date']."')";
$result = mysql_query($sql1);
}
header("Location: attendance.php");
}
?>
你好上面是我的代码,一切似乎都工作正常。有姓名的学生列表,rollno 也出现在成员表中,提交时,出席学生的状态到缺席或出席工作正常,它进入到出席记录个人,示例提交 20 名学生的记录,20 行添加不同的当前状态,但是学生姓名和 rollno 将变为 Null.... 我目前删除了 rollno 和 studentname,因为只有第一个学生姓名重复了 20 次,而且 rollno 也是如此。
<?php
if (($_POST["MM_insert"] == "reg")){
foreach($_POST['present'] as $student_id => $value) {
$sql = "UPDATE members SET current = '".$value."' WHERE memberid = '".$student_id."' ";
$result = mysql_query($sql);
$sql1 = "INSERT INTO student_attendance (department, semester, session, subject, current, percent, date) VALUES ('".$_REQUEST['department']."','".$_REQUEST['semester']."','".$_REQUEST['session']."','".$_REQUEST['subject']."','$value','".$_REQUEST['percent']."','".$_REQUEST['date']."')";
$result = mysql_query($sql1);
}
header("Location: attendance.php");
}
?>
请帮我纠正它,我不能使用具有更多值的 foreach 函数你能告诉如何使用 while 或 for 下面的代码,所以所有学生姓名,包括状态在内的卷都提交到出席视图表?