Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. <?php
  2.  
  3. rebuild_tree(1, 1);
  4.  
  5. function rebuild_tree($parent_id, $left) {
  6.  
  7. // The right value of this node is the left value + 1
  8. $right = $left+1;
  9.  
  10. // Get all children of this node
  11. $this->db->select('id');
  12. $this->db->from('geo');
  13. $this->db->where('parent_id', $parent_id);
  14. $result = $this->db->get();
  15.  
  16. foreach ($result->result() as $row) {
  17. $right = $this->rebuild_tree($row->id, $right);
  18. }
  19.  
  20. // We've got the left value, and now that we've processed
  21. // the children of this node we also know the right value
  22. $this->db->where('id', $parent_id);
  23. $this->db->update('geo', array('lft' => $left, 'rgt' => $right));
  24.  
  25. // Return the right value of this node + 1
  26. return $right+1;
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement