I've got a mysql table called categories, with a few fields: as shown in the create statement below:
It's for a system that needs to support unlimited subcategories. The root categories have a parentID of NULL, and the others have a parentID matching the catID of it's parent category. I want to write a fuction that prints out the entire category structure like this:
CREATE TABLE `categories` (
`catID` int(11) NOT NULL auto_increment,
`parentID` int(11) default NULL,
`name` varchar(255) NOT NULL default '',
PRIMARY KEY (`catID`)
The only way I can think of doing it is having lots of SELECT queries to find the child categories of each category. Is it possible to do this with one mysql SELECT query, and then manipulate the results in PHP to print an output similar to the one above?
Thanks in advance!