我有一个mysql查询,其中按发布日期对每个帖子进行分组。我希望能够回应每天发生的帖子数量,知道一种方法吗?
到目前为止,这是我写的,确实每天都会发布一个新的<div>
。
$trendQuery = "
SELECT DATE(timestamp) AS ForDate,
COUNT(*) AS NumPosts
FROM trends
WHERE `trend` = '" . $_GET['graph'] . "'
GROUP BY DATE(timestamp)
ORDER BY ForDate
";
$result = mysql_query($trendQuery);
while ($row = mysql_fetch_array($result)) {
echo'
<div>
<p>Here is where I want to say how many posts that happened!</p>
</div>
';
}
最佳答案
您已经设置好查询。要回显结果,您只需要引用别名(在您的情况下ForDate
和NumPosts
$trendQuery = "
SELECT timestamp AS ForDate,
COUNT(*) AS NumPosts
FROM trends
WHERE `trend` = '" . $_GET['graph'] . "'
GROUP BY timestamp
ORDER BY ForDate
";
$result = mysql_query($trendQuery);
while ($row = mysql_fetch_array($result)) {
echo'
<div>
Date: '.$row['ForDate'].' ---- Number of Posts: '.$row['NumPosts'].'<br />
</div>
';
关于php - 回显每组的行数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20047047/