winterain Posted November 27, 2008 Share Posted November 27, 2008 Hi all, Ok, so my title might have been a little confusing. I'm writing a simple news list section, and all is done except for the final part which I'm stuck in. Which is a list of Months for the user to select, which will then show the list of articles in that month. My current query is like this : $query_dates = " SELECT DATE_FORMAT( date, '%M %Y' ) AS date_text, DATE_FORMAT( date, '%m') AS month FROM design_news ORDER BY date DESC"; Which lists the months of EVERY entry, so I'm getting an output like: November 2008 November 2008 November 2008 October 2008 October 2008 October 2008 What I need to achieve is : November 2008 October 2008 Regardless of how many entries. Can anyone guide/help me out please? Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/134489-solved-how-can-i-create-a-querycode-that-categorize-a-list-of-months-by-months/ Share on other sites More sharing options...
JonnoTheDev Posted November 27, 2008 Share Posted November 27, 2008 You need to add a GROUP BY claus to the sql GROUP BY YEAR(date) Quote Link to comment https://forums.phpfreaks.com/topic/134489-solved-how-can-i-create-a-querycode-that-categorize-a-list-of-months-by-months/#findComment-700294 Share on other sites More sharing options...
winterain Posted November 27, 2008 Author Share Posted November 27, 2008 Thank you very much! GROUP BY Month(date) and it worked beautifully. Thanks for the quick reply, because I was about to pull my hairs out trying to study search results which suggested for each looping through arrays. Quote Link to comment https://forums.phpfreaks.com/topic/134489-solved-how-can-i-create-a-querycode-that-categorize-a-list-of-months-by-months/#findComment-700301 Share on other sites More sharing options...
JonnoTheDev Posted November 27, 2008 Share Posted November 27, 2008 Sorry, yes month is the grouping Quote Link to comment https://forums.phpfreaks.com/topic/134489-solved-how-can-i-create-a-querycode-that-categorize-a-list-of-months-by-months/#findComment-700339 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.