What should I do if I use php to design a mysql-Netease building? How to store data in a database?

Source: Internet
Author: User
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:

  1. 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.
  2. 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.
  3. 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:

  1. 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.
  2. 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.
  3. 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.