I am looking to create a list in the following format:
2012 (2)
- January (1)
- March (1)
2011 (1)
- March (1)
from am array of dates in the following format:
Array
(
[0] => Array
(
[year] => 2012
[month] => 3
)
[1] => Array
(
[year] => 2012
[month] => 1
)
[2] => Array
(
[year] => 2011
[month] => 3
)
)
this list is provided from the following query, and i’m open to suggestions as how to return the data as well. This was the most logical step for me.
SELECT YEAR(post_date) as `year`, MONTH(post_date) as `month` FROM posts ORDER BY post_date DESC
I’m at a dead end here. I don’t know if I’m not seeing something obvious or if I’ve made this too complicated but I can’t figure out where to go from here.
Assuming you might have multiple rows with the same month/year:
This works as you requested, with this input data:
It outputs this:
*updated to show year counts too