Possible Duplicate:
What is the most efficient/elegant way to parse a flat table into a tree?
php / Mysql best tree structure
I have a table in my database full of groups, each group row has a parent id until the last parent id is 0, making a pyramid. For example:
id: 1 name: staff parent: 0
id: 2 name: communications team parent: 1
id: 3 name: web department parent: 2
Now that can go on forever down the lines, so what I want to do is by using one sql statement giving the web department id it will pull all of the parent groups until the parent is 0.
Is that possible within an sql statement? How could I do that?
so what I want to do is by using one sql statement giving the web department id it will pull all of the parent groups until the parent is 0.
I suppose I don't understand, it sounds like you're retrieving them from the current entry, until the parent is 0... so from the current ID to 0. Can you rephrase that? – David Feb 03 '12 at 22:12