Stulley Posted July 18, 2007 Share Posted July 18, 2007 Hey all, hows it all goin? Here's an issue I've spent the last 8 hours trying to get my head around, I'm pretty sure the answer is simple enough, but I just cannot work it out, any help would be much appreciated...even just a function name or something... I have a very simple message board setup. The browse menu will look end up like below, all dynamically fed from a database, which is currently setup as: [articleID] [articleDate] [articleText] 23 2007-07-18 Lorem ipsum dolor.... The 'articleDate' field is a DATE type, formatted yyyy-mm-dd. All posts should be sorted ascending, latest first. I want nothing to be hard coded, so there could be 2 posts in any month, or 200, or there could be no posts in any year. 2007 June - #1 - #2 August -#1 September -#1 -#2 2008 January -#1 . . . . . So on and so on. So far, I've toyed with array_unique(), as well as multi-dimensional arrays, but I'm really not sure if this is the right approach. I'd post code but I'm not sure there's any point, what I'm really looking to find out is the method to use, rather than code snippets, so if anyone has achieved this, how did you do it? I'm happy as to teach myself whatever I need to know, problem is I don't know what I need to know... It's the first time I've tackled something like this, and more often than not my initial way of achieving a result is the wrong way... Any ideas at all would be great, thanks. Stulley Quote Link to comment Share on other sites More sharing options...
trq Posted July 18, 2007 Share Posted July 18, 2007 Its all in your query. Something like.... SELECT articleID, articleDate, articleText, DATE_FORMAT(articleDate,'%M') AS articleMonth, DATE _FORMAT(articleDate,'%Y') AS articleYear FROM tbl GROUP BY artcileYear ORDER BY articleDate; Quote Link to comment Share on other sites More sharing options...
Stulley Posted July 19, 2007 Author Share Posted July 19, 2007 Cheers Thorpe, I've experimented with the SQL you sent thru, I think I understand what it's supposed to do and I've managed to get it operational, though I don't really understand what I'm meant to end up with as a result? Of the 13 records I've got in the DB, only 3 are being returned, and in not much of a sorted or chronological order it would seem. Is it possible to have SQL effectively produce a recordset which has a group of items for each present year, then a group oof items for each present month? Or will I need to do some data manipulation stuff once I've pulled it from the DB??? Appreciate the response, Stulley Quote Link to comment 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.