Home > Article > Backend Development > Use PHP to simply implement comment systems such as 'Changyan'
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:
Create test data as follows:
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.
Part of the data is shown below:
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.
The data display effect is as follows:
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!