I'm building a task system in php/mysql, imagine I have the following structure:
id | parentid
1 0
2 1
3 1
4 1
5 4
A parentid of 0 means there are no sub items.
So basically, I need to query all items that have a parentid of 1.
In a tree view example I'd get:
1
--2
--3
--4
But I also need to grab all the other subitems:
1
--2
--3
--4
---5
I hope this clears up what I need, this only goes into 3 levels, but I could very well have a huge number of levels.
How should I approach this in MYSQL? Getting a full list of all items with a specific parentid and ALL the other subitems?
Is this even a possible without knowing a limit? Maybe approach this via server side? (but then again, when to stop?)