I have below recursive function in my model with CI, working. In my controller, i need to check if function worked correctly like:
if($this->my_model->level_corrector($id_page,$level)) echo 'Levels are corrected';
But as the function always return false (to end the recursion), I couldn't figure out how to achieve my goal.
  function level_corrector($id_page_of_parent,$level_of_parent)
  {
    $sql = "
    SELECT id_page, id_parent, level
    FROM page 
    WHERE id_parent = $id_page_of_parent";
    $query = $this->db->query($sql);
    if($query->num_rows() > 0)
    {
      $result = $query->result_array();          
      foreach ($result as $r)
      {
        $data = array('level'=>$level_of_parent+1);
        $this->db->where('id_page', $r['id_page']);
        if($this->db->update('page', $data))
        {
           $this->level_corrector($r['id_page'],$level_of_parent+1);
        }
        else
        {
           // let me handle it what to do
           return false;
        }
      }
    }
    else
    { //  again let me handle it to log a message or sth
       return false; // (2)
    }
    return true; // (3) means it all gone right, so I can move on.
  }
