Product classification, multi-level tree structure of the forum, mailing lists and many other places we all encounter this problem: how to store multi-level structure of data?
In the application of PHP, it is usually a relational database that provides back-end data storage, which can save large amount of data and provide efficient data retrieval and update service. However, the basic form of relational data is a criss-cross table, and it is a planar structure, so if we want to store the multilevel tree structure in the relational database, we need to make a reasonable translation work. Next I will see what I saw and some practical experience and everyone to explore.
There are basically two common design methods for hierarchical data storage in a flat database:
Adjacent directory mode (adjacency list model)
Pre-sorted traversal tree algorithm (modified preorder tree traversal algorithm)
I am not a computer professional, and have not learned anything about data structure, so these two names are my own in accordance with the literal meaning of flipping, if wrong, please give more advice.
These two things sound like scary, but it's very easy to understand. Here I use a simple food catalogue as our sample data. Our data structure is this:
Food
|
|---Fruit
| |
| |---Red
| | |
| | | |--cherry
| |
| |---Yellow
| |
| |--banana
|
|---meat
|
|--beef
|
|--pork
In order to take care of those English mess PHP enthusiasts
Food: Foods
Fruit: Fruit
Red: Pink
Cherry: Cherry
Yellow: Yellow
Banana: Banana
Meat: Meat
Beef: Beef
Pork: Pork
http://www.bkjia.com/PHPjc/446964.html www.bkjia.com true http://www.bkjia.com/PHPjc/446964.html techarticle Product Classification, multi-level tree structure of the forum, mailing lists and many other places we all encounter this problem: how to store multi-level structure of data? In the PHP application, provide the background number ...