PHP:快速线程评论问题
我基本上是在尝试编写一个简单的线程评论系统,用户可以在其中对其他用户的评论进行评论。它将只允许一级评论。
数据库中的评论表类似于: - ID - 文本 - 时间戳 -parent_id(可以为NULL)
我的问题是我应该如何查询评论及其子评论(评论)?我只是不确定它们将如何放置在数组中,以及如何正确循环和输出它们。
非常感谢您的帮助=)
I'm basically trying to code a simple threaded comments system where users can comment on other user's comment. It'll allow only one level of comments.
The comments table in the database is something like:
- id
- text
- timestamp
- parent_id (can be NULL)
My question is how should I query the comments and their children (comments)? I'm just not sure how they would be places in the array, and then how to loop and output them properly.
Your help is much appreciated =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果只有一层深,您可以获取所有评论并将它们合并到您想要的结构中。你可以这样做:
If its only one level deep, you could get all comments and munge them into the structure you want. You could do something like this :
以下是有关如何处理此问题的相当详细的说明:
http://mikehillyer。 com/articles/managing-hierarchical-data-in-mysql/
Here is a fairly detailed explanation on how to handle this:
http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/