I'm trying to...
- Set some query parameters and filters.
- Get the total number of matching rows.
- Set limit and offset.
- Get the results
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?