![]() |
Hierarchical Data
I've come across a problem I can't exactly figure out. The problem at hand is with categories and unlimited subcategories. I've done quite a bit of research on the subject and it seems that Adjacency List Model is the best approach for what I'm needing. The Nested Set Model would be ideal optimizing queries but it supports at most two children and only allows one one parent for each node. That is the problem I'm running into.
The only problem with the Adjacency List Model is the fact that getting all categories and subcategories and grouping them together properly with the children under the proper parents doesn't allow for optimized queries and only works properly using recursion. Below is an example of why it's not optimized: Code:
function pull_categories ($parent_id = 0)So the question I have for you, does anyone know any other better ways to accomplish what I'm after? Anyone know any data structures or any types of trees that would allow for better optimizing the code? |
I've only skimmed over your post so if this of no use, I do appologise. Have you tried a "Modified Preorder Tree Traversal" (lol who the hell came up with that name)?
It's a very flexible system, you can read a good article on it here. Thanks to gcbdm for originally posting it in this thread. |
The link you posted doesn't help as it only supports two children for each parent. I've read that article and many others and none seem to give a helping hand on any ideas.
The only thing I can think that would be out there that could possibly help is some type of data tree structure that I'm not familiar with currently. |
The modified preorder tree traversal methods supports as many children as you need per parent. I've already implemented it with 10+ children on certain parents.
PHP Code:
My table structures were: sql Code:
Code:
"category_id","name","lft","rgt" |
| All times are GMT. The time now is 06:20 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0