CodeIgniter Active Record - Get number of returned rows
Have a look at the result functions here:
$this->db->from('yourtable');[... more active record code ...]$query = $this->db->get();$rowcount = $query->num_rows();
AND, if you just want to get a count of all the rows in a table
$table_row_count = $this->db->count_all('table_name');
This goes to you model:
public function count_news_by_category($cat){ return $this->db ->where('category', $cat) ->where('is_enabled', 1) ->count_all_results('news');}
It'a an example from my current project.
According to benchmarking this query works faster than if you do the following:
$this->db->select('*')->from('news')->where(...); $q = $this->db->get(); return $q->num_rows();