在使用数据库中提交结果时,使用3个单选按钮(Present,Absent,Late)出勤时出现了问题。 但是对于其他字段,数据正在成功记录:我进行了深入搜索,发现in如何使用forach循环进行处理,但另一方面,它也反转了其他字段:
下面是我的代码。
<tbody>
<?php
$counter=0;
$qry_std_by_class="select
student_class_tbl.student_REG_number,
student_tbl.first_name as fn,
student_tbl.lastname,
accademic_year.year_name
FROM student_class_tbl
INNER JOIN classes_tbl
on student_class_tbl.class_ID=classes_tbl.class_ID
INNER JOIN student_tbl
on student_class_tbl.student_REG_number=student_tbl.student_REG_number
INNER JOIN accademic_year
on student_class_tbl.accedemic_id=accademic_year.accademic_year_ID";
$query = $dbh->prepare($qry_std_by_class);
$query->execute();
$rslts = $query->fetchAll(PDO::FETCH_OBJ);
if($query->rowCount() > 0)
{
foreach($rslts as $rslt)
{
$regnumber=$rslt->student_REG_number;
$fname=decrypt($rslt->fn,$key);
$lname=decrypt($rslt->lastname,$key);
$academic=$rslt->year_name;
?>
<tr>
<td><?php echo $regnumber ?>
<input type="hidden" value="<?php echo $regnumber; ?>" name="reg_number[]">
</td>
<td><?php echo htmlentities($fname)?>
<input type="hidden" value="<?php echo htmlentities($fname); ?>" name="first_name[]">
</td>
<td><?php echo htmlentities($lname)?>
<input type="hidden" value="<?php echo htmlentities($lname); ?>" name="last_name[]">
</td>
<td><?php echo htmlentities($academic)?>
<input type="hidden" value="<?php echo htmlentities($academic); ?>" name="academic[]">
</td>
<td><?php echo $regnumber ?></td>
<td class="attend-record">
<div class="form-group">
<input type="radio" name="attendance_status[<?php echo htmlentities($counter) ?>]" value="1" ><label for="present">Present</label>
<input type="radio" name="attendance_status[<?php echo htmlentities($counter) ?>]" value="0">Absent
<input type="radio" name="attendance_status[<?php echo htmlentities($counter) ?>]" value="2" >Late
</div>
</td>
</tr>
<?php
$counter++;
}
}
?>
</tbody>
这是处理数据的代码的第二部分:
<?php
if(isset($_POST['submit_attendance']))
{
$on_date = date('y-m-d');
$time = date("H:i:s");
$teacherID = $_SESSION['t_id'];
$school_code = $_SESSION['skl_code'];
date_default_timezone_set('Africa/Cairo');
foreach($_POST['attendance_status'] as $id=>$attendance_status) {
// $countrgs=count($_POST['reg_number']);
//
// for($i=0; $i < $countrgs; $i++) {
$student_REG_number = $_POST['reg_number'][$id];
$names = $_POST['first_name'][$id];
$attendance_status = $_POST['attendance_status'][$id];
$qry_insert_atte = "INSERT INTO attendance_tbl (
student_REG_number,
names,
on_date,
school_code,
state,
teacher_ID,
time
) VALUES (
:student_REG_number,
:names,
:on_date,
:school_code,
:attendance_status,
:teacherID,
:time
)";
$qry = $dbh->prepare($qry_insert_atte);
$qry->bindParam(':student_REG_number',$student_REG_number, PDO::PARAM_STR);
$qry->bindParam(':names',$names, PDO::PARAM_STR);
$qry->bindParam(':on_date',$on_date, PDO::PARAM_STR);
$qry->bindParam(':school_code',$school_code, PDO::PARAM_STR);
$qry->bindParam(':attendance_status',$attendance_status, PDO::PARAM_STR);
$qry->bindParam(':teacherID',$teacherID, PDO::PARAM_STR);
$qry->bindParam(':time',$time, PDO::PARAM_STR);
$qry->execute();
$mssg="<div class='alert alert-success col-xs-12 col-md-6 col-xl-6'>
<span class='glyphicon glyphicon-info-sign'></span> Attendance Saved!
<a href='' class='close' data-dismiss='alert' aria-label='close' style='text-decoration:none;'>×</a>
</div>";
}
}
}
?>
数据提交过程中的结果
这是我的搜索结果:
答案 0 :(得分:0)
尝试此查询,我按Student_class_tbl.student_REG_number ASC添加了订单
select
student_class_tbl.student_REG_number,
student_tbl.first_name as fn,
student_tbl.lastname,
accademic_year.year_name
FROM student_class_tbl
INNER JOIN classes_tbl
on student_class_tbl.class_ID=classes_tbl.class_ID
INNER JOIN student_tbl
on student_class_tbl.student_REG_number=student_tbl.student_REG_number
INNER JOIN accademic_year
on student_class_tbl.accedemic_id=accademic_year.accademic_year_ID order by
student_class_tbl.student_REG_number ASC