gpt4 book ai didi

php - 显示最近输入的评论

转载 作者:行者123 更新时间:2023-11-29 02:51:08 25 4
gpt4 key购买 nike

我有一个帖子表和一个评论表,对于单个帖子,其中会添加一些评论。有一个 php 表,我在其中显示数据。
在此表中,我想在添加帖子时显示帖子的最新评论。

帖子表,添加帖子的地方:

       Posts 
+-------+---------+
| id | Post |
+-------+---------+
| 1 | ABC |
| 2 | DEF |
| 3 | GHI |
+-------+---------+

评论表,其中将向特定帖子添加评论数量:

   Comments
+----------+---------+
| Post_id | Comment |
+----------+---------+
| 1 | A |
| 1 | D |
| 3 | F |
| 3 | V |
| 3 | B |
+----------+---------+

这里的post_id取自post表的id。

我希望带有最新评论的帖子显示在此表中:

<table>
<thead>
<tr>
<th>Post</th>
</tr>
</thead>
<tbody>
<?php foreach($results as $key=>$row) { ?>
<tr>
<td><?php echo $row['Comment'];?></td>
</tr>
<?php } ?>
</tbody>
</table>

例如:

+----------+---------+
| Post | Comment |
+----------+---------+
| ABC | D |
| GHI | B |
+----------+---------+

提前致谢。

最佳答案

这对你有用!

SELECT comment FROM comments WHERE comment_id = (SELECT comment_id 
FROM comments WHERE post_id = 1 ORDER BY comment_id DESC LIMIT 1);`

表结构

Table Structure

表格数据

Table Data

查询结果

Query Result

关于php - 显示最近输入的评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35574641/

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