Jump to content

Looping Query


dyluck

Recommended Posts

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!

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/203662-looping-query/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.