I’m trying to create a monthly archives of a news table
$q = mysql_query("SELECT * FROM news GROUP BY post_date DESC" );
while ($r = mysql_fetch_assoc($q)){
$a= $r['post_date'] ;
echo date('M Y ',strtotime($a)). '<br />';
}
This one is giving me something like
Feb 2010
Feb 2010
Feb 2010
Feb 2010
Jan 2010
Jan 2010
Dec 2009
Dec 2009
How do I group this so every entry on a particular month will be grouped together as one entry (something similar to wordpress monthly archives)
like:
Feb 2010
Jan 2010
Dec 2009
my MySql post_date column is datetime with a default value of 0000-00-00 00:00:00
SELECT
YEAR(post_date) AS year,
MONTH(post_date) AS month
FROM
news
GROUP BY
YEAR(post_date),
MONTH(post_date)
ORDER BY
YEAR(post_date) DESC,
MONTH(post_date) DESC
There seems to be an error am I doing something wrong?
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampplite\htdocs\baguioTrader\ est.php on line 15
2010-02-13
$q = mysql_query("SELECT YEAR(post_date) AS year, MONTH(post_date) AS month
FROM news GROUP BY YEAR(post_date), MONTH(post_date)
ORDER BY YEAR(post_date) DESC, MONTH(post_date) DESC" );
while ($r = mysql_fetch_assoc($q)){
$a= $r['post_date'] ;
echo $a .'<br />';
//echo date('M Y ',strtotime($a)). '<br />';
}