Implementing Recursive Comments in PHP/MySQL

后端 未结 6 1249
-上瘾入骨i
-上瘾入骨i 2020-12-18 09:11

I\'m trying to write a commenting system, where people can comment on other comments, and these are displayed as recursive threads on the page. (Reddit\'s Commenting system

6条回答
  •  感动是毒
    2020-12-18 10:12

    Try using a nested set model. It is described in Managing Hierarchical Data in MySQL.

    The big benefit is that you don't have to use recursion to retrieve child nodes, and the queries are pretty straightforward. The downside is that inserting and deleting takes a little more work.

    It also scales really well. I know of one extremely huge system which stores discussion hierarchies using this method.

提交回复
热议问题