You don't have to query the data twice. Nor should you use the queries in your example.
Pull everything in one shot:
SELECT DATE(`start`) as start_date, TIME(`start`) as start_time, ...etc... FROM shifts ORDER BY `start`
Iterate the results and store them in a multi-dimensional array, building a list of dates as you go:
$shifts = array();
foreach ( $results as $v ) [
$shifts[$v->start_date][$v->should_be_a_primary_id] = $v;
}
Storing the data this way makes the job of grouping into time ranges - e.g. 12-5, 3-6, 4-9, etc. - and then counting the values a simple task.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community