Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- rebuild_tree(1, 1);
- function rebuild_tree($parent_id, $left) {
- // The right value of this node is the left value + 1
- $right = $left+1;
- // Get all children of this node
- $this->db->select('id');
- $this->db->from('geo');
- $this->db->where('parent_id', $parent_id);
- $result = $this->db->get();
- foreach ($result->result() as $row) {
- $right = $this->rebuild_tree($row->id, $right);
- }
- // We've got the left value, and now that we've processed
- // the children of this node we also know the right value
- $this->db->where('id', $parent_id);
- $this->db->update('geo', array('lft' => $left, 'rgt' => $right));
- // Return the right value of this node + 1
- return $right+1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement