dyluck Posted June 2, 2010 Share Posted June 2, 2010 Hi there, Hopefully someone can answer this. Lets say I have a table that has a bunch of categories / subcategories. I don't know how deep the subcategories go but each category references it's parent. How would I build a statement to list each last level category and its parents? ID SID PARENT NAME LINK 1 2 Books http://www.website.com/books 2 2 Cars http://www.website.com/cars 3 2 1 Fantasy http://www.website.com/books/fantasy 4 2 1 SiFi http://www.website.com/books/sifi 5 2 1 Romance http://www.website.com/books/romance 6 2 3 Wizards http://www.website.com/books/fantasy/wizards 7 2 2 Coup http://www.website.com/cars/coup 8 2 7 4WD http://www.website.com/cars/coup/4WD Query Result: 1. Books > Fantasy > Wizards ~ http://www.website.com/books/fantasy/wizards 2. Books > SiFi ~ http://www.website.com/books/sifi 3. Books > Romance ~ http://www.website.com/books/romance 4. Cars > Coup > 4WD ~ http://www.website.com/cars/coup/4WD So on and so fourth. Thanks so much for your help! Quote Link to comment https://forums.phpfreaks.com/topic/203662-looping-query/ Share on other sites More sharing options...
fenway Posted June 4, 2010 Share Posted June 4, 2010 There are stickies that talk about retrieving such data. Quote Link to comment https://forums.phpfreaks.com/topic/203662-looping-query/#findComment-1067910 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.