The magic word is 'recursion', a self-referencing function.
the basic idea is this:
-find the top level category.
function getChildren($piParentCategory)
{
- find all children for $piParentCategory
-- For each child found, call this function again, from inside this function, but this time, with the child's ID so it will gather the children of this child: getChildren($piChildID)
}
That will get you a list of the top level, all it's sublevels, all the levels under that, etc.
There is a trick for getting the sublevels to indent; you have to send an indent-level along:
- set indentlevel to zero
- find top level, call getChildren(parentid, indentlevel)
function getChildren(parentid, &$inndentlevel
{
- increase indentlevel (so that all children found will get a higher indentlevel)
-- find the kids, call this function witht the new indent level
- when all the children are processed, decrease the indent level
}
Just make sure you send the indent level as a parameter by reference, or it won't work :-)