I am working on one Join query in CodeIgniter. Query run perfectly fine.
The problem is $query->num_rows()
.This is how I write my join query.
$this->db->select('related colums');
$this->db->from('table1 as t1');
$this->db->join('table2 as t2', 't1.id = t2.id', 'left outer');
$this->db->join('table3 as t3', 't1.id_second = t3.id', 'left outer');
$this->db->where('t1.column', $some_varibale);
$this->db->order_by("t1.column", "desc");
$query = $this->db->get();
$query_result = $query->result_array();
$number_of_row = $query->num_rows(); // This line of code is not working properly.
print_r($number_of_row);
// To check result is empty or not.
if(!empty($query_result)){
echo 'not empty';
} else {
echo "empty";
}
The problem:
When I print the $number_of_row
it gives me 13 but when I print $query_result
it will show only one row which is correct result.(I have double checked it)
so the problem is I was expecting that $query->num_rows()
will return me 1 if I get only one row in the result.
I have the cross check it when I get an empty result then it will show 0 as expected. but as described before when I get one row in result it will show 13 number.
I am aware of count
and it will work but the question is why this $query->num_rows()
not working correctly?
I didn't get that what am I doing wrong?
count($query_result)
? – Therinenum_rows()
worked as intended. Maybe if you can share more of the actual code, otherwise we can't replicate the problem. – Naylorresult_array()
: github.com/bcit-ci/CodeIgniter/blob/3.1-stable/system/database/… Just a guess: Is$query_result
an array of arrays or just a one-dimension array. Useprint_r($query_result)
or debug Codeigniter itself. – Ariosoprint_r
for result it was same as described in question, for info: this query is the only query in the function of model. @Arioso is join query is doing any thing wrong? – Police