我正在嘗試在我的網站中創建新聞存檔。我寫了這個代碼:使用PHP和MySQL創建月度存檔
$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
謝謝,但它不工作... – Alireza
試試這個,它會工作。請檢查我寫的SQL語句中的列名。 –
非常感謝你我的親愛的朋友。工作中。 – Alireza