I'm building a simple nested category system on a database... shouldn't be too difficult. I've done it before but I can't find the code and I'm having a huge problem trying to figure out how to get an array of parents off a category. Here is the database:
fileCategories:
catID int not null primary key auto_increment
catName varchar(32) not null
catDescription text not null
catParent int not null
So basically, catParent will contain a catID of it's parent category, or zero(0) if it's a root category.
So say I have the following values inside the table at this point (format: catID : catName : catParent):
1 : Games : 0 // root category
2 : Quake : 1 // under "Games"
3 : Half-Life : 1 // under "Games"
4 : Movies : 2 // under "Games" -> "Quake"
5 : Movies : 3 // under "Games" -> "Half-Life"
6 : Gameplay : 4 // Under "Games" -> "Quake" -> "Movies"
7 : Trailers : 4 // Under "Games" -> "Quake" -> "Movies"
So what I want to do, when calling a function and passing a catID, is get an array with all the categories above it.
So, say I call getCategories(7), I would expect an array with something like:
[0] -> "Games"
[1] -> "Quake"
[2] -> "Movies"
[3] -> "Trailers"
But I'm having a problem designing the recursive function that will do this. Any help would be greatly appreciated.