[英]Echo number of rows per group by
I have a mysql query in which I group each post by the date is was posted. 我有一个mysql查询,其中按发布日期对每个帖子进行分组。 I want to be able to echo the amount of posts that happened each day, know a way? 我希望能够回应每天发生的帖子数量,知道一种方法吗?
Here is what I've written so far which does post a new <div>
for each day it was posted. 这是我到目前为止编写的内容,它每天都会发布一个新的<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>
';
}
You have your query pretty much set up. 您已经设置好查询。 To echo the results, you simply need to refer the columns with the alias name, in your case ForDate
and NumPosts
要回显结果,您只需要使用别名(例如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>
';
Create a view of your trend query and inner join it with "Select (Id or day that you want to merge) From trend" 创建趋势查询视图,并通过“从趋势中选择(要合并的ID或日期)”将其内部联接
i hope that helps 我希望有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.