Hi,
I have this data:
id | parent_id | lft | rgt | name
=====================================
1 | 0 | 1 | 8 | abc
2 | 3 | 5 | 6 | jkl
3 | 1 | 2 | 3 | def
4 | 0 | 9 | 10 | mnno
5 | 1 | 4 | 7 | ghi
I need to traverse this hierarchy in this order (ids): 1 > 3 > 5 > 2 > 4
How can I achieve this?
Assume that I want to find the next node of node_x.
if (node_x_rgt - node_x_lft == 1) {
next_node_lft = node_x_rgt + 1;
} else {
next_node_lft = node_x_lft + 1;
}
This formula works only in some cases (node ids 1,3,5,2). The next node of node 2 should be 4.