I am trying to list all the previous months in which posts have been made and display the number of posts, for example
2011
November (14)
October (12)
April (3)
2010
December (2)
etc etc
The following code is how I am attempting to make this work however it doesnt actually return any results and I cannot seem to wrap my head around why.
$sql = "SELECT nid, ndate FROM weaponsnews
ORDER BY ndate DESC";
$result = $db->query($sql);
$data = array();
while($row = $result->fetch_assoc())
{
$year = date('Y', strtotime($row['ndate']));
$month = date('m', strtotime($row['ndate']));
$data[$year][$month][] = $row;
}
$result->free();
foreach($data as $_year => $_months)
{
echo $_year. "<br>";
foreach($_months as $_month => $_entries)
{
$mentries = count ($_entries);
echo $_month. " (" .$mentries. ")";
}
}