CodeIgniter Forums
$query->num_rows(); can not get the number of rows - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: $query->num_rows(); can not get the number of rows (/showthread.php?tid=18572)



$query->num_rows(); can not get the number of rows - El Forum - 05-11-2009

[eluser]test2009[/eluser]
I retrieve the records Ifm ODBC / Access database 2007
it works
$this->db->where('EMAIL', $strSearch);
$data['query']= $this->db->get('MYTABLE');

I can list the records all OK.
But
in view file
echo $query->num_rows();
gives -1 result

What is wrong?


$query->num_rows(); can not get the number of rows - El Forum - 05-11-2009

[eluser]Dam1an[/eluser]
Having a quick look at the ODBC driver, it just returns the value of odbc_num_rows which is a PHP function
That function returns -1 on error, so its a PHP/ODBC fault, not a CI problem

Are you getting anything in your error logs? (Make sure you have logging enabled)


$query->num_rows(); can not get the number of rows - El Forum - 05-11-2009

[eluser]test2009[/eluser]
yes, I hv enabled the logs at 4 level
No error with database.
the result is -1 even though there are records returned from query.


$query->num_rows(); can not get the number of rows - El Forum - 05-15-2009

[eluser]pickupman[/eluser]
I recently ran into this same problem using an Access database. If you look into the CI library /system/database/drivers/odbc_result.php, the function num_rows() is null. The function is commented that ODBC does not support it. I used the following query.
Code:
//Query DB for number of rows in result
$rows_query = $this->db->query('SELECT Count(CUSTOMER.CUSTOMERKEY) AS Count
FROM CUSTOMER');

//Result saved as an array        
$rows = $rows_query->row_array();

echo $rows['Count'];



$query->num_rows(); can not get the number of rows - El Forum - 05-15-2009

[eluser]Jondolar[/eluser]
Why are you calling $query->num_rows();

You are using an ActiveRecord call that returns an array. You have no object to call num_rows() against.

If you want to continue to use ActiveRecord you need to call:
$this->db->count_all('my_table');

Basically, you are mixing ActiveRecord functions with the database class functions