Welcome Guest, Not a member yet? Register   Sign In
Pagination: Can this be improved?
#6

[eluser]mcr_rm[/eluser]
I do it like this in my models...doesn't save you from overhead of calls to the db but it works for me. I then pass [results] to my view and [total] to the pagination class through my controller. Rather than making two calls from the controller I make one, however say you didn't want the total that is extra overhead that could be avoided doing as above functions.

Code:
public function _getAll($limit=10, $offset=0)
    {
        
        $this->db->flush_cache();
        $this->db->start_cache();
        $this->db->from($this->db_table);

        
        $this->db->stop_cache();
        
        $return=array();
        $return['total']=$this->db->count_all_results();
        
        $this->db->limit($limit, $offset);
        $this->db->order_by('id', 'DESC');
        $query = $this->db->get();
        $return['results']= $query->result();
        
        
        return $return;

    }

PS clearly you might want to pass in what you want to order results by also!


Messages In This Thread
Pagination: Can this be improved? - by El Forum - 01-17-2010, 03:31 PM
Pagination: Can this be improved? - by El Forum - 01-17-2010, 03:52 PM
Pagination: Can this be improved? - by El Forum - 01-17-2010, 04:02 PM
Pagination: Can this be improved? - by El Forum - 01-17-2010, 04:22 PM
Pagination: Can this be improved? - by El Forum - 01-17-2010, 04:49 PM
Pagination: Can this be improved? - by El Forum - 01-17-2010, 05:33 PM
Pagination: Can this be improved? - by El Forum - 01-17-2010, 05:49 PM
Pagination: Can this be improved? - by El Forum - 01-17-2010, 06:07 PM
Pagination: Can this be improved? - by El Forum - 01-17-2010, 06:29 PM



Theme © iAndrew 2016 - Forum software by © MyBB