I have a list of categories stored in mysql db. The categories can have child categories at any deep level user want.
Database Table
id name parents
1 Apparel
2 Appliances
46 Apparel 1
47 Child Apparel 1
48 Other Child Category 46
Now parents column tells me which category is a child of which parent. What best data structure algorithm I can use here without recursion in PHP?
This article explains how to store a tree based model, with the ability to look up children without recursive queries.
If the child nodes can be children of multiple parents, you should check out this model
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.