i have read so many blogs and links to save the hierarchical data in mysql database like nested set modal *Transitive Clousure Modal* Child Parent Hierchy . but i am little bit confuse can any body please suggest me what is the best method to store hierarchical for more than one root.
e.g
Root1
|
|---Child 1
| |--Child 1 of 1
| |--Child 2 of 2
|
Root 2
|
|--Child 2
| |--Child 1 of 2
| |--Child 2 of 2
Thanks in adavance :)
When you use a table to store a hierarchy, each object in the hierarchy needs a parent. So your node might have these columns:
With this table layout any parentless node (that is, any node with
parentid = 0
) is a root node. You can have as many of these in your table as your application requires.The example you showed might be represented like this: