--- Paul Burney <paul.lists@burney.ws> wrote: > on 3/26/03 9:18 PM, Leif K-Brooks at > eurleif@buyer-brokerage.com appended > the following bits to my mbox: > > > I have a table with a tree. Thing is, I need to > generate a view of it like: > > Category > > Sub-category > > Sub-sub-category > > Another sub-category > > Another category > > Sub-category > > > > Any way to do this, without using a huge number of > queries? Using MySQL. > > This comes upon the list every few weeks. Check the > archives for more > information. > > Basically, in MySQL there is no way to do it without > using a large number of > queries if you have the traditional table layout > with a record_id and a > parent_id in each, so that the table relates to > itself. > There is one way - grab the entire table and loop it into a multi-array and process it with PHP. $categories[parent_id][category_id] So all subcats of category_id 5 are in $categories[5] Of course this will not be the best approach for large category structures. You can use basically the same code flow as the recursive loop Paul posted to go thru this array. instead of query for subcats you already have them in the array. __________________________________________________ Do you Yahoo!? Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop! http://platinum.yahoo.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php