在php中构建一个mysql数据库报告

时间:2015-10-06 03:39:05

标签: php mysql report

如何在MySQL查询中获得如下结果: enter image description here

3 个答案:

答案 0 :(得分:1)

首先,您必须从数据库表中获取所有员工,然后迭代他们的ID以获得所需格式的出勤报告

$qry_employee = mysqli_query($connection, "SELECT employee_id FROM employee");
if($qry_employee)
{
    if(mysqli_num_rows($qry_employee) > 0)
    {
        while ($employees = mysqli_fetch_array($qry_employee))
        {
            $qry_attendance = mysqli_query($connection, "SELECT e.employee_id, e.employee_name, 
                                a.am_id, a.am_out, a.pm_in, a.pm_out, a.ot_in, a.ot_out, a.date 
                                FROM employee e 
                                JOIN attendance a ON e.ID = a.ID 
                                WHERE a.date BETWEEN '2015-08-01' AND 2015-08-30' 
                                AND e.employee_id = ".$employees['employee_id']."
                                ORDER BY e.ID ASC");

            // your report generation here
        }
    }
    else
    {
        echo "No result found to display.";
    }
}

答案 1 :(得分:0)

SELECT `DATE`,`am IN`,`am OUT`,`pm IN`,`pm OUT`,`OT IN`,`OT OUT` 
FROM `EMPLOYEE ATTENDANCE LOGS` 
WHERE `ID No.` = '3' 
AND `Dept.` = `ADMIN/OFFICE` 
AND `Name` = 'GOJO CRUZ, CHARLOTTE'

答案 2 :(得分:0)

请参阅Andrews回答。您只能看到一个员工的原因是因为在他的查询中,ID号= 3。

要为所有员工生成此项,您需要一份员工ID列表,并为每个员工运行此查询。

作为替代方案,您可以在没有ID限制的情况下运行它,但您必须按应用程序代码中的ID对数据进行分组,然后