Javascript-how can the hierarchical data structure of the comment system be most suitable?

Source: Internet
Author: User
I want to write a wordpress Comment system by myself. Of course, the wordpress data table structure is used. However, there is a bit of doubt about how to find this level. The database structure is as follows, where the id is automatically generated. postid indicates the article where the comment is made, and approved indicates whether the comment has passed...

I want to write a wordpress Comment system by myself. Of course, the wordpress data table structure is used.
However, there is a bit of doubt about how to find this level.

The database structure is as follows:

The id is automatically generated, the postid indicates the article where the comment is located, the approved indicates whether the review is performed (0 indicates no), and the parent indicates the parent Id of the comment (reply to the comment ), content is content.

The normal output result should be

Here, how can I write php to achieve this effect? I don't know the concept of data structure calling in my mind. Its Process

The first is to call this post with the postid of 99, so that the database content is the same as my first one.
Next, I want to output comments with a level of 0, but when will other levels be inserted?

Reply content:

I want to write a wordpress Comment system by myself. Of course, the wordpress data table structure is used.
However, there is a bit of doubt about how to find this level.

The database structure is as follows:

The id is automatically generated, the postid indicates the article where the comment is located, the approved indicates whether the review is performed (0 indicates no), and the parent indicates the parent Id of the comment (reply to the comment ), content is content.

The normal output result should be

Here, how can I write php to achieve this effect? I don't know the concept of data structure calling in my mind. Its Process

The first is to call this post with the postid of 99, so that the database content is the same as my first one.
Next, I want to output comments with a level of 0, but when will other levels be inserted?

Isn't this a typical tree structure? Just flatten it into the array.
Postid is used to make it possible for you to query each node separately.
As for how to insert it, if you plan to insert it at a time, it will be related to the code of the rendering template. The focus is on your html and css.

It can also be divided into two queries: first, the normal rendering page only has a level-1 comment, and then fill in the supplementary information in an ajax query (Baidu post it ).

However, the paging issue is troublesome.

Like zhihu, the complexity is reduced as much as possible. Of course, zhihu has no center floor and only one reply XXX. This implementation is much simpler and there is no need to worry about paging.

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.