我正在尝试在我的网站上创建一个新闻档案。我写了这段代码:
$sql_result = $db->query("
SELECT *,COUNT(id) AS itemCount
FROM post
GROUP BY DATE_FORMAT(date, '%Y-%m') DESC ");
while ( $row = $db->get_row( $sql_result ) ) {
$datetime = strtotime($row['date']);
$tday = date("Y-m", $datetime);
$count = $row['itemCount'];
echo "Month: {$tday} - News Number: {$count}<br>";
}
这是结果:
Month: 2013-06 - News Number: 4
Month: 2013-05 - News Number: 3
Month: 2013-04 - News Number: 4
Month: 2013-03 - News Number: 3
我的问题是,如何在该月之后的每个月显示新闻标题?例如这样的:
Month: 2013-06 - News Number: 4
-news number 1 for this month
-news number 2 for this month
-news number 3 for this month
-news number 4 for this month
Month: 2013-05 - News Number: 3
-news number 1 for this month
-news number 2 for this month
-news number 3 for this month
Month: 2013-04 - News Number: 4
-news number 1 for this month
-news number 2 for this month
-news number 3 for this month
-news number 4 for this month
Month: 2013-03 - News Number: 3
-news number 1 for this month
-news number 2 for this month
-news number 3 for this month