Hi everyone.
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:Code: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?Code:Web Design CSS HTML Web Hosting Pre Sales Domain Names cPanel cPanel tutorials Email
Thanks in advance!
James



I had the same bother myself, and since then have come across a class off the web whereby you do one query, the results are sorted by ascending order of ID.




Bookmarks