Implementing Recursive Comments in PHP/MySQL

后端 未结 6 1248
-上瘾入骨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 09:52

    It's just a suggestion, but since I'm facing the same problem right now, How about add a sequence field (int), and a depth field in the comments table, and update it as new comments are inserted.

    The sequence field would serve the purpose of ordering the comments. And the depth field would indicates the recursion level of the comment.

    Then the hard part would be do the right updates as users insert new comments.

    I don't know yet how hard this is to implement, but I'm pretty sure once implemented, we will have a performance gain over nested model based solutions.

提交回复
热议问题