php层次结构评论系统
我想做discus/reddit/之类的评论系统,我的评论数据库中有一个“id_answer”(默认设置为0)字段,当用户回答另一个评论时,该字段是父评论的“id”。
我在数组中有线程的注释,但我不知道如何过滤每个循环以获得如下内容:
评论等级 1($array[id_answer] 为 0)
------ 评论级别 2($array[id_answer] 是 id_of_level_one_comment)
---------------评论3级...
i want to do discus/reddit/ like commenting system, i have an "id_answer" (set to 0 by defaut) field in my comment database and when user answer to another comment this field is the "id" of the parent comment.
I have the comments of the thread in an array but i dont know how to filter filter each loop for get something like this :
comment lvl 1 ($array[id_answer] is 0)
------- comment lvl 2 ($array[id_answer] is id_of_level_one_comment)
--------------- comment lvl 3 ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用数据库中的三个字段;
假设您要显示id为“123”的新闻文章的评论树
当从mysql中选择时,选择具有此thread_id的所有内容:
然后您应该预先解析数组以将子评论提供给其父母,并使用递归显示来显示每个评论评论及其子列表。
例如:
这给出了以下结果:
我将 ORDER BY 等留给您,因为它不会造成任何问题。
Use three fields in your database;
Let's say you want to show the comment tree for your news article with id "123"
When selecting from mysql, select everything with this thread_id:
Then you should pre-parse your array to give the child comments to their parents, and use a recursive display to show each comment and its child list.
For exemple:
This give the following result:
I leave the ORDER BY and such to you, as it should not pose any problem.