gpt4 book ai didi

php - 回显每组的行数

转载 作者:行者123 更新时间:2023-11-29 13:26:33 25 4
gpt4 key购买 nike

我有一个 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>
';
}

最佳答案

您的查询已经基本设置完毕。要回显结果,您只需引用具有别名的列,在您的情况下为 ForDateNumPosts

$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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com