Forum Moderators: coopster & phranque

Message Too Old, No Replies

Representing Hierarchical Data

         

Robber

9:49 am on May 28, 2003 (gmt 0)

10+ Year Member



Hi,

I am writing some scripts for a new site at the moment where there is a lot of hierarchical data that needs to be represented (basically loads of parent child relationships). Im using a php/mysql setup.

I did this on a previous website using the "adjacency model" where you have a database table such as:

empID ¦ name ¦ managerID
1 bob 0
2 bill 1
3 ben 1

This worked pretty well but wasnt so good when you consider a situation where a child can have many parents - you run into normalization problems. So I have been looking around for other solutions. I came across the "nested sets" technique which is based on mathematical graph theory, it sounds like it could do the trick but I was wondering if anyone had used it and had any thoughts, and particularly if it has been used in situations where a child can have many parents.

Cheers

bcc1234

10:18 am on May 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Usea table that maintains the relationship.

employee
-id
-name

manager
-id
-name

em_man_rel
-empl_id
-man_id

or is all data is of the same class

em_rel
-parent_empl_id
-child_empl_id

daisho

4:47 am on May 31, 2003 (gmt 0)

10+ Year Member



Do a search on the boards. We did a very involved thread on this in the last month. It was in relation to security models. There is lots of very good information to be had by many people with many different views.

daisho.