How can I sort in PHP a SQL query grouping by date…
I have this table
id date Title
1 2012-12-19 11:00:00 Value 10
2 2013-01-04 09:00:00 Value 15
3 2013-01-04 20:00:00 Value 18
4 2013-01-04 21:00:00 Value 5
5 2013-01-07 09:00:00 Value 8
6 2013-01-07 09:40:00 Value 11
7 2013-01-07 11:00:00 Value 12
And I would like to sort by month like so
December 19
11:00:00 Value 10
January 04
09:00:00 Value 15
20:00:00 Value 18
21:00:00 Value 5
January 07
09:00:00 Value 8
09:40:00 Value 11
11:00:00 Value 12
Try below query and use PHP loop to get your desired result. You just need to split id, time and title values inside your PHP loop to format data for display.
OUTOUT
SQL fiddle: http://sqlfiddle.com/#!2/ec3a8/6
UPDATE:
OUTPUT
PHP CODE: I’m assuming you have array like below on the basis of above query output.
Final PHP output: