如果连续缺席5天,则显示学生详细信息

时间:2015-08-13 09:17:17

标签: php

我在显示连续5天缺席的学生详细信息时遇到问题。我写了一个sql查询,如:

$res = $this->db->findAll("SELECT 
student_id,attn_date,count(is_absent) as absent FROM 
sg_students_attendance where is_absent=1 GROUP BY student_id ORDER BY 
attn_date desc");

我申请的条件是:

foreach($res as $rec)
{  

    $abs=$rec['absent'];
    $abs1=5;

    if($abs1==$abs)
    {
        echo "<tr>";
        echo "<td>".$rec['student_id'];
        echo "<td>".$rec['absent'];
        echo "</tr>";
    }

}

我正在让学生详细了解那些缺席5天而不是连续缺席的人。什么是查询?

1 个答案:

答案 0 :(得分:0)

您可以使用PHP代码

执行此操作
$res=$this->db->findAll("SELECT student_id,attn_date,is_absent as absent FROM sg_students_attendance where is_absent=1 ORDER BY student_id,attn_date desc");

PHP代码

$count = 0;
foreach($res as $rec)
{
     $abs=$rec['absent'];
     if($abs == 1)
         $count++;
     else
         $count = 0;

     if($count == 5)
     {
         echo $rec['student_id'] . ' is absent for continuous 5 or more days<BR>';
         $count = 0;
     }
}