Welcome Guest, Not a member yet? Register   Sign In
num_rows() function does not work
#1

Hello Community,

Following is a code example.

Code:
       $this->db->select('*');
       $this->db->distinct();
       $query = $this->db->get('products');
       /*does not work*/
       echo $query->num_rows(); // this line does not work
       echo count($query->result_array()); // this line works

If I print_r($query) then num_rows, then it shows empty.

Please guide.

Regards,
Sam
Reply
#2

Does this?
Code:
$query = $this->db
  ->distinct()
  ->get('products')
  ->result_array();


echo $query->num_rows();

(get the result array first)
Reply
#3

(07-22-2015, 10:00 AM)swand Wrote:
Code:
       $this->db->distinct();
       $query = $this->db->get('products');
       /*does not work*/
       echo $query->num_rows(); // this line does not work
       echo count($query->result_array()); // this line works

If I print_r($query) then num_rows, then it shows empty.

$query->num_rows is not the same thing as $query->num_rows(), and $query->num_rows generally will be empty until you've called $query->num_rows() or some result method on $query.

If $query->num_rows() does not work (as opposed to $query->num_rows), what database driver are you using?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB