Reputation: 13141
I'm trying to...
Here's what I initially tried:
$this->db->select(<aggregation, subqueries>);
$this->db->from('users');
$this->db->where(<complex filters>);
$total = $this->db->count_all_results();
$this->db->limit($limit, $offset);
$query = $this->db->get();
$result = $query->result();
But calling count_all_results
calls _reset_select
internally meaning I have to do the first step again - not very DRY.
How would you achieve this in a simple, clean way?
Upvotes: 1
Views: 842
Reputation: 11
Just use Query Builder Caching
$this->db->start_cache();
$this->db->select(<aggregation, subqueries>);
$this->db->from('users');
$this->db->where(<complex filters>);
$this->db->stop_cache();
$total = $this->db->count_all_results();
$this->db->limit($limit, $offset);
$query = $this->db->get();
$this->db->flush_cache();
$result = $query->result();
Upvotes: 1