问题描述
我正在CodeIgniter中处理一个Join查询.查询运行得很好.问题是$query->num_rows()
.这就是我编写联接查询的方式.
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";
}
问题:
当我打印$number_of_row
时它给了我13,但是当我打印$query_result
时它只显示了一行是正确的结果.所以问题是我期望$query->num_rows()
如果我只得到一行结果,就会返回1.
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.
当我得到一个空结果时,我会对其进行交叉检查,然后它将显示为0.但是如前所述,当我得到一行结果时,它将显示13个数字.
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.
我知道count
,它可以工作,但是问题是为什么这个$query->num_rows()
无法正常工作?
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?
推荐答案
尝试一下:
$number_of_row = $this->db->affected_rows();
让我知道是否可行
这篇关于当结果不为空时,num_rows()不返回正确的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!