leetee Posted October 28, 2009 Share Posted October 28, 2009 I have the following query to my categories table: SELECT l1.id as lev1_id,l2.id as lev2_id,l3.id as lev3_id,l1.category AS lev1, l2.category as lev2, l3.category as lev3 FROM categories AS l1 LEFT JOIN categories AS l2 ON l2.parentCat = l1.id LEFT JOIN categories AS l3 ON l3.parentCat = l2.id WHERE l1.parentCat = NULL Which outputs something like: ------------------------------------------------------- lev1_id | lev2_id | lev3_id |lev1 | lev2 | lev3 | ------------------------------------------------------ 1 | 4 | 7 |makeup | lipstick | wet look 1 | 4 | 8 |makeup | lipstick |matt 1 | 5 | 9 |makeup | mascara| black 2 | 11 | NULL|skincare|creame | NULL 3 | 12 | 13 |haircare |hairspray| Xtra Hold I want to be able to display this data as a tree with 3 levels. I know a foreach is a good place to start but I get stuck after that. Any help would be much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/179410-displaying-hierarchical-data-as-tree/ Share on other sites More sharing options...
Daniel0 Posted October 28, 2009 Share Posted October 28, 2009 Have a look at these topics. They might help you. http://www.phpfreaks.com/forums/index.php/topic,274461.0.html http://www.phpfreaks.com/forums/index.php/topic,273616.0.html http://www.phpfreaks.com/forums/index.php/topic,273665.0.html Quote Link to comment https://forums.phpfreaks.com/topic/179410-displaying-hierarchical-data-as-tree/#findComment-946642 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.