简体   繁体   English

如何与父评论一起显示对评论的回复?

[英]How to display reply to comments together with the parent comments?

Hi I'm wondering what's the best apppraoch to display reply to comments together with the parent comments. 嗨,我想知道与父注释一起显示对注释的回复的最佳方法是什么。


1 way I learned is to store the replies and parent comments in the same table, while giving the replies an index "parent comment id". 我学到的一种方法是将回复和父评论存储在同一张表中,同时给回复一个索引“父评论ID”。 The "parent comment id" would be null for the parent comments. 父评论的“父评论ID”为null。 When displaying the comments, simply display all together and use an if (parent comment id=null) statement to append the replies to parent comments. 在显示注释时,只需将所有内容一起显示,然后使用if(父注释id = null)语句将答复附加到父注释。

Pseudo-code to demonstrate: 伪代码演示:

Mysql comment table: comment_id|parent_comment_id|comment_body|... MySQL注释表:comment_id | parent_comment_id | comment_body | ...

Php: PHP的:

foreach 的foreach

If (parent_comment_id=null) { Display comment_body } 如果(parent_comment_id = null){显示comment_body}

If (parent_comment_id<>null) { Display comment_body } 如果(parent_comment_id <> null){显示comment_body}

end of foreach foreach结束

The other way I'm thinking is to store the replies in a separate table, and pull the replies only when they have a parent comment displayed. 我在想的另一种方法是将答复存储在单独的表中,并仅在显示父注释时才拉出答复。

Pseudo-code to demonstrate: Mysql comment table: comment_id|comment_body 演示的伪代码:Mysql注释表:comment_id | comment_body

Mysql reply table: reply_id|parent_comment_id|reply body Mysql回复表:reply_id | parent_comment_id |回复正文

Php: foreach php:foreach

Display comment_body 显示comment_body

If (parent_comment_id=comment_id) { Display reply_body } 如果(parent_comment_id = comment_id){显示Reply_body}

end of foreach foreach结束


What is the better way to do it? 有什么更好的方法呢?

Thanks a lot, 非常感谢,

You can try NoSQL DB for this . 您可以为此尝试NoSQL DB。 ex MongoDB. 前MongoDB。 it's better then MySQL. 比MySQL好。

Use Json Display Result. 使用Json显示结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM