I\'m using a complex SQL query in a Codeigniter model with a limit applied. I\'d like to count the total number of rows that would have been found if the limit and offset had no
One way I can think is to have variable $count when you call your function, and it will go something like this:
function your_function($count = FALSE) {
$this->db->select(...)
//before limit you do this:
if($count != FALSE):
return $this->db->get->result_array()
else :
return $this->db->limit($limit, $offset)->get()->result_array();
endif;
}
This way you can call function two time - one for count and the other for limit query:
$count = count($this->your_function(TRUE));
$data['query] = $this->your_function();