So I'm calling in data from a DB where each record is associated with a (column) 'start_time', 'no_shows', 'cancelled', and 'attended'
I want to go through the results of this SELECT and count the number of no shows, cancellations and attended on a WEEKLY basis (based on the start_time). How can I achieve this?
The user will provide a date range and the DB will select the records based on that date range. Now this date range will then have to be split by weeks and then get the count. I'm totally stuck on the counting by weeks part. This is what I have so far:
All it does is just organize the data into separate arrays without any counting. Attached is a preview of the output.
// Multidimensional Array with [boolean][week #]
$no_shows_weekly = [
'no_show' => [],
'week' => []
];
$cancelled_weekly = [
'cancelled' => [],
'week' => []
];
$attended_weekly = [
'attended' => [],
'week' => []
];
foreach($result as $r) {
$start_time = new DateTime($r['start_time']);
if($r['is_no_show'] == 0 && $r['is_cancelled'] == 0) {
array_push($attended_weekly['attended'], 1);
array_push($attended_weekly['week'], date_format($start_time, "W"));
}
else {
array_push($attended_weekly['attended'], 0);
array_push($attended_weekly['week'], date_format($start_time, "W"));
}
array_push($no_shows_weekly['no_show'], $r['is_no_show']);
array_push($no_shows_weekly['week'], date_format($start_time, "W"));
array_push($cancelled_weekly['cancelled'], $r['is_cancelled']);
array_push($cancelled_weekly['week'], date_format($start_time, "W"));
}
echo json_encode(array(
'success'=> 1,
'msg'=>
array(
'No Shows' => $no_shows_weekly,
'Cancellations' => $cancelled_weekly,
'Attendend' => $attended_weekly
)
));
Any suggestions or help is greatly appreciated!