Home  >  Article  >  Backend Development  >  Use PHP to simply implement comment systems such as "Changyan"

Use PHP to simply implement comment systems such as "Changyan"

王林
王林forward
2019-08-22 11:42:482796browse

Referring to comment systems such as "Duosuo" and "Changyan", I implemented a simple comment system using PHP language. It also records the implementation process of the two methods (recursive and non-recursive), and analyzes the advantages and disadvantages of the two methods. How to implement the front-end is not shown.
First design the database as follows:

Use PHP to simply implement comment systems such as ChangyanCreate test data as follows:

Use PHP to simply implement comment systems such as Changyan

The specific implementation plan is as follows (implemented on the ThinkPHP framework):
1. Recursive method
Advantages: The implementation code is simple, and if the level of comments is fixed below 5 levels If so, it is recommended to use this method so that the front-end can easily implement this data result.
Disadvantages: If the level of comments is not fixed, the front end will not be able to display the comment information, and if there are too many levels, it will consume a lot of memory. What’s more terrible is that the database must be queried for each recursion, and the performance will be reduced. Greatly reduced.

Use PHP to simply implement comment systems such as Changyan

Part of the data is shown below:

Use PHP to simply implement comment systems such as Changyan

2. Non-recursive method ( Stack mode implementation)
Advantages: Only query the database once, good performance. N-level comments can be realized, and the front-end can also display them well.
Disadvantages: The code is slightly complicated. For fixed-level comments, the front-end display of comments is more complicated.

Use PHP to simply implement comment systems such as Changyan

The data display effect is as follows:

Use PHP to simply implement comment systems such as Changyan

The above content implements a simple comment system, To learn more about PHP, please visit the PHP Chinese website: PHP Video Tutorial

The above is the detailed content of Use PHP to simply implement comment systems such as "Changyan". For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete