how to count the number of rows returned by query in Codeigniter with Datamapper how to count the number of rows returned by query in Codeigniter with Datamapper codeigniter codeigniter

how to count the number of rows returned by query in Codeigniter with Datamapper


Following is availab in CI - checkout this page - http://codeigniter.com/user_guide/database/results.html

$query->num_rows()

The number of rows returned by the query. Note: In this example, $query is the variable that the query result object is assigned to:

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

so that in your example above you need to try

$details->num_rows();


If you just want to count the total rows found, call the count() method instead of get().

$u->where('us_email_id', $username);$u->where('us_password', $password1);$total = $u->count();

But, if you also need the data, then you can simply call get(), and after that use PHP count() to count how many elements are there inside the all property of the object.

$u->where('us_email_id', $username);$u->where('us_password', $password1);$u->get();$total = count($u->all);

You can check out the documentation for more details.


If the password was encrypted and try again

or if all the data part is fine the try to use the following code

$this->db->where(array('us_email_id' => $username,'us_password' => $password1));echo $this->db->count_all_results('users');