nested data, copying and moving tree branches
Posted: Tue Feb 01, 2005 6:21 am
Hi
I've been messing with this problem some days. I have tried MPTT method to collect and organize data in hieracrhical structure, but still donno, is it the best method or should i continue with next theme:
DB:nodes
node_id
node_ppath
node_depth
DB:datas
data_id
data_node_id
data_type
data_title
data_content
data_order
data_created
data_modified
data_uid
data_gid
data_chmod
Now i can make selects, inserts, updates and deletes quite simple, but i haven't get solution, how to copy or move branches of tree to another location. Copying node or first childs of node goes well, but how would you copy (moving bases propably to the same method) all the children of some node?
Let me give you example structure for nodes (ppath is parent path presentation with dot separated list):
Now i would like to copy branch starting from id 4 to id 11. That means all items between 4-7 will be copied and final table looks like this:
I suppose, these is no straight method with sql to do this, but i should make some php functions to deal with case. Any function suggestions?
This could be also on php code forum, but didin't know which one is better in this case. Administrators could move this post if required.
Thanks,
Marko
I've been messing with this problem some days. I have tried MPTT method to collect and organize data in hieracrhical structure, but still donno, is it the best method or should i continue with next theme:
DB:nodes
node_id
node_ppath
node_depth
DB:datas
data_id
data_node_id
data_type
data_title
data_content
data_order
data_created
data_modified
data_uid
data_gid
data_chmod
Now i can make selects, inserts, updates and deletes quite simple, but i haven't get solution, how to copy or move branches of tree to another location. Copying node or first childs of node goes well, but how would you copy (moving bases propably to the same method) all the children of some node?
Let me give you example structure for nodes (ppath is parent path presentation with dot separated list):
Code: Select all
id ppath depth
1 0 0
2 1 1
3 1 1
4 1.2 2
5 1.2.4 3
6 1.2.4.5 3
7 1.2.4 2
8 1 1
9 1.8 2
10 1.8.9 3
11 1.8.9 3
12 1.3.7 3Code: Select all
13 1.8.9.11 4
14 1.8.9.11.13 5
15 1.8.9.11.13.14 6
16 1.8.9.11.13 5This could be also on php code forum, but didin't know which one is better in this case. Administrators could move this post if required.
Thanks,
Marko