i need to list total post article archive by years and months like this :
Output(my need):
2014
January(31)
February(28)
March(0)
April(130)
May(450)
June(0)
July(0)
August(0)
September(0)
October(520)
November(20)
December(31)
PHP:
$sql = "SELECT title, YEAR(FROM_UNIXTIME(timestamp)) AS YEAR,
MONTHNAME(FROM_UNIXTIME(timestamp)) AS MONTH,
COUNT(*) AS TOTAL
FROM article GROUP BY YEAR, MONTH ORDER BY YEAR DESC, MONTH ";
$newsdata = DB->fetch($sql);
$currentYear = null;
foreach($newsdata AS $news){
if ($currentYear != $news['YEAR']){
echo '<ul>'.$news['YEAR'].'</ul>';
$currentYear = $news['YEAR'];
}
echo '<li>'.$news['MONTH'].' '.$news['TOTAL'].'</li>';
}
My code worked but print only month if posted article in this month.
Ouput:
2014
January(31)
February(28)
April(130)
May(450)
October(520)
November(20)
December(31)
I need to list all month and print total article for each month. if month not posted article print (0)
for this month.
how do can i fix my problem? my code/way is true?!