Jump to content

Parsing Hierarchical Data


GlassCasket

Recommended Posts

I read http://www.sitepoint.com/article/hierarchical-data-database and had a few questions. I posted on their forums no one seems to be able to help.

 

Great article, read it several times.

 

I have the following structure:

 

HTML Code:

- TB
    - cat a
    - cat b
        - sub-cat b
        - sub-cat b
        - sub-cat b
    - cat c

 

My table structure is 'category_id, name, lft, rgt'.

 

The category_id is linked in with my products table.

 

Any ideas how I can display my products in the following fashion:

 

HTML Code:

 

- TB
    - cat a
        - product from sub category a
    - cat b
        - sub-cat bb
            - product from sub category b
        - sub-cat bbb
            - product from sub category bbb
            - product from sub category bbb
        - sub-cat bbbb
    - cat c
        - product from sub category c

 

Thanks!

Link to comment
Share on other sites

Initially i thought using a query like this:

 

SELECT cat.category_id, cat.category_name, prod.cat_id, prod.name FROM cat, prod WHERE prod.cat_id=cat.category_id ORDER BY category_id ASC

 

but your aim is to have sub categories and stuff which makes it difficult for me. Probably someone else may resolve it.

Link to comment
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.