We will encounter such problems in product classification, multi-level tree-structured forums, mailing lists and many other places: How to store multi-level structured data?
In PHP applications, the backend data storage is usually a relational database, which can save large amounts of data and provide efficient data retrieval and update services. However, the basic form of relational data is a criss-crossed table, which is a flat structure. If you want to store a multi-level tree structure in a relational database, you need to perform reasonable translation work. Next, I will discuss with you what I have seen and heard and some practical experiences.
There are basically two common design methods for storing hierarchical data in flat databases:
Adjacency list model (adjacency list model)
Pre-sorted tree traversal algorithm (modified preorder tree traversal algorithm)
I am not a computer major, and I have never learned anything about data structures, so I translated these two names according to their literal meanings. If I am wrong, please let me know. Please give me some advice.
These two things may sound scary, but they are actually very easy to understand. Here I use a simple food directory as our example data. Our data structure is like this:
Food
|
|---Fruit
| |
| |- --Red
| | |
| | |--Cherry
| |
| |---Yellow
| >
||--PorkTo take care of those PHP enthusiasts whose English is a messFood: foodFruit: fruitRed: RedCherry: CherryYellow: YellowBanana: BananaMeat: Meat Beef: BeefPork: Pork
http://www.bkjia.com/PHPjc/446964.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446964.html