Page 1 of 1

group mysql results by year, list months

Posted: Mon Oct 04, 2010 3:21 pm
by invisibled
hey everybody,

i am trying to build a query and just can't quite get my head around it. I need to display press releases from a database, but, They need to be grouped by year, then display all the months. The data will be one press release per month, the date will be a datetime column called "created_at" and here is a visual example of how i want the output. e.g:

2010
january
february
march
etc..

2009
january
february
etc..

any help would be greatly appreciated!

Re: group mysql results by year, list months

Posted: Mon Oct 04, 2010 6:39 pm
by Christopher
ORDER BY the date descending. Then as you loop through the results -- when the year or month changes -- insert the proper heading.