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

王林
Release: 2023-04-07 08:44:01
forward
2758 people have browsed it

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!