Prashant Kumbhar
Prashant Kumbhar

Reputation: 59

How to get total number of record in the query using codeigniter?

This is my code

$attendanceDetail = $this->common->getWhere('tbl_attendance', 'date', $allDate);
$total = $attendanceDetail->num_rows();
if($total >0 )
{
    echo "record found";
}
else{
    echo "Not Found";
}

How to get a total number of record in the query result?

Upvotes: 0

Views: 381

Answers (2)

Prashant Kumbhar
Prashant Kumbhar

Reputation: 59

$attendanceDetail = $this->common->getWhere('tbl_attendance', 'date', $allDate);
$total = count($attendanceDetail);
if($total >0 )
{
   echo "record found";
}
else{
    echo "Not Found";
 }

Upvotes: 1

Vipin Kr. Singh
Vipin Kr. Singh

Reputation: 672

Try this: Put this method in your Model

public function count_records($table_name) {
     return $this->db->count_all($table_name);
}

count_all is query builder class method which returns total no of records in a table see here

and inside your controller method use it like this:

$total_records = $this->your_model->count_records('put_table_name_here');

Upvotes: 1

Related Questions