I would like to ask the MYSQL statement for comments by page, which can cover the comments of the building

Source: Internet
Author: User
Ask for the MYSQL statement for comments by page. you can retrieve comments by page when building comments. for example, 20 entries per page. however, my comments can be commented again. comments can be commented again ..... the building can be built. that is to say, A comments can have subcomments, and A subcomments can have subcomments. that is, Sun comment of. sun's comments can also have comments. A's great grandson asks for comments on the page to get comments on MYSQL, which can be used to build comments on the building.
You need to retrieve comments by page. for example, 20 comments per page.
However, my comments can be commented again. comments can be commented again.
That is to say, A comments can have subcomments, and A subcomments can have subcomments. that is, Sun comment of. sun comments can also have comments. A's great comments ...... unlimited layering.

The comment field is: id, and parent_id. if it is the original comment, parent_id is 0. if it is a descendant comment, parent_Id is the father's id.

I want to limit 20 original comments and the comments of these 20 sons and grandchildren using one statement.
Ask everyone.

------ Solution --------------------
To meet your requirements, you do not only need to use id and parent_id (the adjacent list algorithm) to solve the problem.
You need to convert the data organization method to the pre-order traversal algorithm (also known as the left-right value algorithm and pre-sorting algorithm)

You can search for the specific implementation.

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.