Hi. I have a database full of categories. The important fields being id, parent_id and title. Top level categories have a parent_id = 0. Subcategories have their parent_id value set to the id of the parent category. That should be straightforward. I have already written the function getAllCategories( $parent_id = 0 ) which basically SELECTs all the categories from the database with a given parent_id. I use this function throughout the site already. So, here's my problem. If I were to list (or put in some sort of structurally similar array) all the categories of my site, with their child categories like so: category subcategory subcategory subcategory subcategory subcategory category subcategory subcategory subcategory category Code (markup): etc, how would I go about doing that? I'm not bothered about the displaying or anything, just the logic behind it to potentially worm through an infinite number of subcategories, then, when there are no more subcategories for that particular category, go back up a level and worm through all the subcategories for that one, etc, etc, until there are no more categories left to check through. Sort of like http://www.avivadirectory.com/sitemap.php Any decent ideas whatsoever will receive some reputation points.
Ok, for anyone else that's interestedm here's the answer: http://dev.mysql.com/tech-resources/articles/hierarchical-data.html