how to display count in codeigniter?

Today, We want to share with you codeigniter count rows in table.In this post we will show you codeigniter 4 count row, hear for count column in codeigniter we will give you demo and example for implement.In this post, we will learn about Codeigniter Count Row In View & Controller with an example.

Counting the number of returned results with count_all_results()

php codeigniter count row

$query = $this->db->query('SELECT * FROM my_shop');
echo $query->num_rows();

CodeIgniter Active Record – Get number of returned row

$this->db->from('yourshop');
[... more active record code ...]
$query = $this->db->get();
$rowcount = $query->num_rows();

using 1. Function: num_rows()

$this->db->where('EmpID >=', 5);
$query = $this->db->get('Members');
echo $query->num_rows();

// Outputs, 4
if ($query->num_rows() > 0)
{
   foreach ($query->result() as $row)
   {
      echo $row->EmpID;
      echo $row->EmpName;
      echo $row->Designation;
   }
}

2. Function: count_all_results()

$this->db->select('*');
$this->db->from('Members');
$this->db->like('Designation', 'Manager');
echo $this->db->count_all_results();

// Outputs, 2
echo $this->db->count_all_results('Members');

// Outputs, 8

CodeIgniter – Count Number of Row in Table:

echo $this->db->count_all('Members');

// Outputs, 8

Codeigniter Count Rows Of Table

$totalRows = $this->db->count_all('members');
echo $totalRows;

I hope you get an idea about codeigniter count rows in table.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment