Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.