I am working on a system that caters services for small groups of registered members based on their locations (cells). The current issue I am having is displaying a list of services against the count of those present on a particular date. The query is correct but I am having issues formatting the table correctly
the data should display as so
SERVICE | DATE1 | DATE2 | etc
HEALTH | 5 | 3 | etc
DENTIST | 10 | 20 | etc
This is currently what I have done:
<div class="col-sm-12">
<div class="box-body no-padding">
<table class="table cell-border" id="members">
<thead>
<th>Service</th>
<?php foreach($result as $g){?>
<th><?php echo $g['date'];?></th>
<?php }?>
</thead>
<tbody>
<tr>
<td><?php echo $g['Service Name'];?></td>
<?php $i=1; foreach($result as $g){ ?>
<td> <?php if($g['Attendance'] == 'NULL') {echo 0;} else { echo $g['Attendance'];}?> </td>
<?php }?>
</tr>
</tbody>
</table>
</div>
Here is the query:
SELECT record_attendance_cell.id, record_attendance_cell.`company_id`,record_attendance_cell.`cell_id`,record_attendance_cell.`member_id`, COUNT(record_attendance_cell.`present`) as `Attendance`, record_attendance_cell.`service_id`,record_attendance_cell.`date`, setting_company.name `Company Name`, setting_cell_group.`location`, `setting_service`.title as `Service Name`
FROM `record_attendance_cell`
LEFT JOIN setting_company
on setting_company.id = record_attendance_cell.company_id
LEFT JOIN setting_cell_group
on setting_cell_group.id = record_attendance_cell.cell_id
LEFT JOIN setting_service
on setting_service.id = record_attendance_cell.service_id
WHERE record_attendance_cell.`present` = 1 AND record_attendance_cell.`date` BETWEEN '$date_from' AND '$date_to'
group by record_attendance_cell.service_id
order by record_attendance_cell.date asc
According to your result and your description. I have come up with this:
Please give it a try (EDITED):
OUTPUT:
http://www.phpwin.org/s/ewbAS6
If you want the attendance to be accumulative, simply change the WHILE loop (ADDED)
OUTPUT
http://www.phpwin.org/s/5umFBA