Support the ongoing development of Laravel.io →
posted 10 years ago
Database
Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

xanfm xanfm Joined 25 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.