If the parent comment has a previous comment, and the sub-comment has a current comment, all methods I can think of now: store all the parent comments in htmlspecialchars and mysql? The disadvantage is that a comment can only be deleted after it is deleted due to harmony. Its Sub-comment... assume that the parent comment = the previous comment; sub comment = Current my comment; all methods that I can think of currently:
- Store all the parent comments in htmlspecialchars and mysql? The disadvantage of doing so is that after a comment is deleted for the sake of harmony, it can only be deleted, and its sub-comment will also appear because it has been written to mysql.
- Store all the parent comments in serialize to the database and recursively traverse them when reading the comments. However, this is just an idea and I don't know how to traverse it.
- Store the reply_id of all comments to the database and read these reply_id at one time during reading. This method is more flexible than the first method and can delete data in real time, but the database consumes too much and requires multiple reads of the database.
These individuals do not feel appropriate. Is there any better way?
Reply content:
Assume that the parent comment = the previous comment; sub comment = Current my comment; all methods that I can think of currently:
- Store all the parent comments in htmlspecialchars and mysql? The disadvantage of doing so is that after a comment is deleted for the sake of harmony, it can only be deleted, and its sub-comment will also appear because it has been written to mysql.
- Store all the parent comments in serialize to the database and recursively traverse them when reading the comments. However, this is just an idea and I don't know how to traverse it.
- Store the reply_id of all comments to the database and read these reply_id at one time during reading. This method is more flexible than the first method and can delete data in real time, but the database consumes too much and requires multiple reads of the database.
These individuals do not feel appropriate. Is there any better way?
I am afraid to say a few things about SQL table design here:
(1) I think it is most appropriate to use Path Enumeration storage for Netease comments, that is:
The composition of the comment ID is:
CommentID | Path
1 |/1
2 |/1/2
3 |/1/3
4 |/1/2/4
If you delete comments No. 2, simply delete all matching ^/1/2 in the Path.
(2) Of course, there is also a more elegant way to use closure tables:
Finally, all the ideas above come from the SQL anti-pattern book.