Codeigniter Count Rows Of Table


Codeigniter Count Rows Of Table : There are several ways developers use to get total number of rows in table. You can use $this->db->count_all(‘table_name’) to get the total rows of a table, this is . Here in this tutorial we are going to explain how you can use database class to get the total row count of a table.


Codeigniter Count Rows Of Table | Query Example

Codeigniter Count Rows Of Table

The syntax and example to count the rows is as –

Syntax

Codeigniter Count Rows Of Table : Query Syntax

$this->db->count_all('table_name');

Where table_name is name of the table.

After running the above query it will give the total count of rows in specified table.

Example

Now suppose we have table “users” and we want to count the number of rows in this table. The example to count rows in “users” table is as –

Codeigniter Count Rows Of Table : Query Example

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

The above example will give you total number of rows in users table. Output will be an integer like : 90.

In case of joins use $query->num_rows() to count the results.


Advertisements

Add Comment

📖 Read More