codeigniter active record get query and query without the LIMIT clause

前端 未结 4 1940
梦谈多话
梦谈多话 2020-12-13 21:41

im using active record, its all working ok but i want to set the $data[\"totalres\"] to the total results, i mean, the same query but without the LI

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-13 22:07

    I would actually suggest the use of CIs query caching.

    To use this, you start the cache, build the query without the limits in place. Run your query to get the full count, then apply the limit and run the query to get your list for your page with the offset you need.

    The cache will remember the variables that have been defined.

    You can then clear the cache for subsequent queries.

    Example

        $this->db->start_cache();
    
        // Where, like, having clauses in here
    
        $this->db->stop_cache();
    
        $count = $this->db->get('table')->num_rows();
    
        $this->db->limit('limit', 'offset');
    
        $result = $this->db->get('table')->result_array();
    
        $this->db->flush_cache();
    

提交回复
热议问题