How to create a payroll report out of an attendance records using PHP
<p>I have database table named: <strong>timesheets</strong> which has the following columns and data:</p>

<pre><code>employee_id  employee_name  year  month  day  timein  timeout  department
1            dave           2016  09     15   8       4        finance
1            dave           2016  09     16   8       4        finance
1            dave           2016  09     17   8       4        finance
2            frank          2016  09     15   8       4        purchase
2            frank          2016  09     16   8       4        purchase
</code></pre>

<p>which records the daily attendance of employees as you can see above. What I want is to create a payroll report from these attendance records using PHP that shows the total number of working hours for each employee with every department in a separate html table like so:</p>

<p><strong>finance department payroll html table</strong></p>

<pre><code>employe_id | employee_name  | total_working_hours
-----------+----------------+---------------------
1          | dave           | 24 (8 hrs * 3 days)
</code></pre>

<p><strong>purchase department payroll html table</strong></p>

<pre><code>employe_id | employee_name  | total_working_hours
-----------+----------------+---------------------
1          | frank          | 16
</code></pre>

<p>Please note that I don't know the ID's of all employees, so the code should just list everyone grouped by department using PHP / MYSQL</p>