计算Codeigniter中数据库查询返回的结果数 [英] Counting the number of results returned by a database query in Codeigniter

查看:159
本文介绍了计算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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆