gijew Posted April 4, 2008 Share Posted April 4, 2008 I'm working on a journal application that creates a sidebar similiar to that of a blog that should group by month and year. Perhaps I'm too tired or perhaps I've been working too much today but this one is beyond me right now. I'm getting weird results and this looks like it should work for me. Anyhoo, I'm using AdoDb to pull out the data so just an FYI From what I know I know that this should be grouping the years and the months correctly but as you can see from the results it isn't. It actually looks like I'm outputting the first row successfully and the rest of the data is coming out as a piece of an array... Thanks for any help you can provide me! Database field `created_on` Data example: 2008-04-03 01:01:01 2008-04-01 12:13:14 2008-01-14 03:04:05 2007-12-25 12:12:12 <?php // PHP Function Function getArchives () { global $db; $SQL = $db->GetAll("SELECT DISTINCT YEAR (created_on) AS `year`, MONTH(created_on) AS `month` FROM journal_categories GROUP BY YEAR(created_on), MONTH(created_on) ORDER BY created_on DESC"); If (Count($SQL) != 0) { ForEach ($SQL AS $REC) { $O .= $REC['month'].'-'.$REC['year'].'<br />'; } } return $O; } ?> ::Output:: 4-2008 4-8 1-8 Link to comment https://forums.phpfreaks.com/topic/99491-trying-to-create-blog-like-archive/ Share on other sites More sharing options...
gijew Posted April 4, 2008 Author Share Posted April 4, 2008 Just an FYI I was too lazy to copy the exact db table contents so the output isn't exactly the same. Using the data provided it would probably output: 4-2008 4-8 1-8 12-7 Just didn't want anyone to get me on that one at least Link to comment https://forums.phpfreaks.com/topic/99491-trying-to-create-blog-like-archive/#findComment-509041 Share on other sites More sharing options...
gijew Posted April 4, 2008 Author Share Posted April 4, 2008 /bump Anyone? Anything? Link to comment https://forums.phpfreaks.com/topic/99491-trying-to-create-blog-like-archive/#findComment-509235 Share on other sites More sharing options...
gijew Posted April 4, 2008 Author Share Posted April 4, 2008 GOT IT thanks to help from someone else!!!! Just thought to post a solution if anyone ever stumbles on this in the future. It's all in the query! mysql_query("SELECT DISTINCT DATE_FORMAT(created_on,'%m-%Y') as dates FROM journal_categories GROUP BY created_on ORDER BY created_on DESC"); Link to comment https://forums.phpfreaks.com/topic/99491-trying-to-create-blog-like-archive/#findComment-509498 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.