gpt4 book ai didi

php - 按同一条目对评论进行分组,按日期排序

转载 作者:行者123 更新时间:2023-11-29 00:53:21 26 4
gpt4 key购买 nike

我有一个名为 comments 的表,其结构如下:

id | entry_id | date | comment

我还有一个名为 entries 的表,其结构如下:

entry_id | title | date | entry

我只想显示最近的评论和添加了这些评论的条目。

现在我正在使用这个查询:

SELECT c.id,
c.date,
c.comment,
e.entry_id,
e.title
FROM entries e
INNER JOIN comments c
ON e.entry_id = c.entry_id
GROUP BY c.date DESC
LIMIT 50

我这样输出结果:

#entry_id
1 hour ago:
Some comment

#entry_id
2 hours ago:
Some comment

评论按日期排序。我想做的只是按相同的 entry_id 对评论进行分组,例如:

#entry_id
1 hour ago:
Some comment

2 hours ago:
Some comment without repeating the `entry_id`

#other entry_id
5 hours ago:
Some comment

我该怎么做?无需为我编写代码,只需说明 将如何执行(例如,用伪代码)。这是像 facebook 或 google+ stream 上的评论分组,我希望你明白我的意思。

最佳答案

用过这个:Grouping arrays in PHP

我认为我不应该写太多关于我的 MySQL 表结构的细节,它是用 PHP 和数组完成的。感谢大家的关注。

$groups = array();

foreach($items as $item)
$groups[$item['value']][] = $item;

关于php - 按同一条目对评论进行分组,按日期排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7288401/

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