Implementation Principle of PHP Infinite Classification

PHP Unlimited Classification

What is PHP Unlimited Classification? Just like creating a new folder under Windows, you can create a new folder under the newly created folder. This will continue in an infinite loop. The same is true for infinite classification. A parent class can separate its subcategories, and a subcategory can separate its subclasses. category, and this continues in an infinite loop. Suppose there is such a three-level classification, News→PHP News→PHP7 comes out. If we want to find the news "PHP7 is out", we can click on the news first, and then click on the PHP news to find out. In other words, we can search down level by level through the grandfather class, and conversely we only need to If you know the parent class of a subclass, you can find it. In this way, when designing the database, we can design an additional field of parent class id to realize the unlimited classification function of PHP.

Introduction to the Principle of Infinite Classification

Infinite classification may seem "high-level", but in fact the principle is very simple. Infinite classification not only requires the ingenuity of the code, but also relies on the rationality of the database design. To satisfy infinite classification, the database needs to have two necessary fields, id and pid. The id is used to identify itself, while the pid is used to indicate the parent id. In other words, each classification record not only describes itself, but also describes another ID that it is most closely concerned about. What seemed like a complicated matter was solved with such a little trick.


Required PHP file

##conn.php Database configuration file

deep.php Recursive infinite classification file

##deep2.php Navigation link file


Create database table

Classification table: named deepcate

QQ截图20161201093751.png

Continuing Learning
||
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!