Jump to content

Recommended Posts

I've encountered this situation a couple of times and usually i solved it by using some php.

So here is the situation.

 

When having to deal with tree structures sometimes it would be nice to have some sort of inheritance and getting all the child items.

 

for example when you have the following tree structure using 2 tables

categories and products

 

category1

-product1

-product2

+category2

-product3

-product4

+category3

-product5

-product6

 

let's say i want all the products in category1 including all the products in the sub categories.(in this case products 1 to 6)

 

what would be the best way to solve this. I am thinking about using a stored procedure for this and using some kind of loop in it. Would this be the best approach ?

I just want methods of solving it I dont want any full working queries or code i just want some hints.

 

ty

 

 

Link to comment
https://forums.phpfreaks.com/topic/127368-solved-tree-structures/
Share on other sites

The storing part is easy using foreign keys

but fetching all lower child elements is a bit trickier.

 

I thought there might be some other neat way besides using a stored procedure but it seems to be the best way to go

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.