如何实现嵌套注释系统? [英] How to implement a nested comment system?
问题描述
什么是实现这种事情的理想方式?我现在在我的头脑中的想法是有一个注释表,并且每个评论都有一个线程标识符和父注释标识符。线程标识符将指示注释属于哪个线程,并且将允许使用WHERE子句的简单MySQL语句。
What would be the ideal way to implement this sort of thing? The idea I have in my head right now is to have a comments table and have each comment have a thread identifier and parent comment identifier. The thread identifier would indicate to which thread the comment belongs to and would allow for a simple MySQL statement using the WHERE clause. Each comment would have an auto_increment identifier as per usual database design and the parent identifier column would indicate which comment this comment is a child of.
这种类型的设计会把最多的数据库设置成一个数据库设计,的压力对PHP的方面的事情,因为它只会有一个SQL调用从一个线程的所有注释。我发现另一个实现是每个嵌套级别有一个SQL查询。这个解决方案会把事情的SQL侧面的压力。
This type of design would put most of the stress on the PHP aspect of things because it would only be one SQL call to get all comments from a thread. Another implementation I found was having an SQL query for each nesting level. This solution would place the stress on the SQL sides of things.
如何实现这一点?目前我很失望,因为我不知道哪个解决方案是最好的解决方案,我对数据库设计,PHP和JQuery仍然很新。
How would SO implement this? Currently I'm at a loss because I am not sure which solution is the "best" solution and I am still quite new to database design, PHP, and JQuery.
感谢。
推荐答案
查看在MySQL中管理分层数据,特别是称为嵌套集模型的部分。你可能需要阅读几遍之前,它有意义(我做),但它是值得的。这是一个非常强大的方法来处理嵌套数据,并只用一个查询检索你想要的部分。
Look at Managing Hierarchical Data in MySQL, specifically the section called "Nested Set Model". You may have to read through it a few times before it makes sense (I did) but it's worth it. It's a very powerful way to work with nested data and retrieve the parts you want with only one query.
在缺点,对于更新,你必须做更多的工作。
On the downside, for updates you have to do a lot more work.
这篇关于如何实现嵌套注释系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!