计算Codeigniter中数据库查询返回的结果数 [英] Counting the number of results returned by a database query in Codeigniter
问题描述
我没有太多运气检测当Codeigniter中的数据库查询返回零结果。我已经很好地读了关于PHP计数函数的注释,但是没有更聪明的!
I am not having much luck detecting when a database query in Codeigniter returns zero results. I have had a good read of the notes on the PHP count function but am none the wiser!
我从控制器调用如下查询/视图:
I call the query/view as follows from the controller:
$data['result'] = $this->search_model->do_search(set_value('name'));
$data['title'] = "Search results";
$this->load->view('search_view',$data);
视图为我生成一个结果表,但是当我尝试并捕获一个空结果时, count总是返回1:
The view generates a results table for me OK, but when I try and trap an empty result, the count always returns 1:
如果count(array($ result)) $ c> if count($ result)
I have tried if count(array($result))
and just if count($result)
那么什么是一个很好的方法来获取计数?我在我的dev笔记本电脑上使用Fedora 13和PHP 5.3.3。
So what's a good way to get the count? I'm using Fedora 13 with PHP 5.3.3 on my dev laptop.
推荐答案
看看 $ query-> num_rows
(< - 可点击)。
Have a look at $query->num_rows
(<- clickable).
这篇关于计算Codeigniter中数据库查询返回的结果数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!