Home >Backend Development >PHP Tutorial >Example of unlimited classification in PHP (imitation Taobao product classification)
2. Add Add several top-level categories
Here fid=0 represents the top category Then add several subcategories for {computer}
Here fid=2, the id 2 is the id of the category {Computer}, if you add the subcategory of {Shoes}, then fid=3 In the same way, if you add a subcategory to {notebook}, fid=6
3. Delete If you want to delete the category {Notebook}, you can do this:
{Notebook} subcategories must also be processed accordingly.
Why is it so troublesome to use recursion instead of deleting it directly like this?
So you can directly delete {ausu}, {hp}? But assuming {ausu} has a subcategory {a1}, and {a1} also has a subcategory {a2}, the data cannot be completely deleted without recursion. 3. Search 1. Find subcategories of {Computer}
2. Find all subcategories of {Computer}
IV. Practical application Add a field `tid` to the data table, the field value is the id of the `type` table to which the record belongs. It must be id and not name, because the value of name may change. For example, query products belonging to the {Computer} category:
That’s it, I hope it will be helpful to everyone. |