Count Query Codeigniter

“Codeigniter Use Count Query, Count Query use With Codeigniter,How to Use Count Query in Codeigniter, Count Query use With Where Condition”

In Codeigniter, Count query is used to count the total rows of the table. How to use this query can be seen below.

In Example :- If you have 20 comments in your comments table and you want to count all the comments of user_id 2. Then count of query will be written in this way.

Count Query Use In Codeigniter

$this->db->select('count(*)');
$this->db->from('comments');
$this->db->where('user_id','2');
$query = $this->db->get();

echo $query->num_rows();