【发布时间】:2012-03-29 04:25:22
【问题描述】:
我正在尝试列出之前发布的所有帖子并显示帖子的数量,例如
2011
November (14)
October (12)
April (3)
2010
December (2)
etc etc
以下代码是我尝试完成这项工作的方式,但它实际上并没有返回任何结果,我似乎无法理解为什么。
$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. ")";
}
}
【问题讨论】: