Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter新手:计算查询结果?_Php_Mysql_Codeigniter - Fatal编程技术网

Php Codeigniter新手:计算查询结果?

Php Codeigniter新手:计算查询结果?,php,mysql,codeigniter,Php,Mysql,Codeigniter,我有我的疑问: $query = $this->db ->get_where('users', array('group_id' => 7, 'active' => 1)); 如果我使用: print_r ($query->result()); 我所要做的就是获取与我的查询匹配的行的总数。我尝试了num_rows和count(),但两个都无法工作 任何帮助都将不胜感激!目前,我只是在我的视图中测试它,但当我弄明白它时,我会将它移到我的模型中 谢谢

我有我的疑问:

$query = $this->db
        ->get_where('users', array('group_id' => 7, 'active' => 1));
如果我使用:

print_r ($query->result());
我所要做的就是获取与我的查询匹配的行的总数。我尝试了num_rows和count(),但两个都无法工作

任何帮助都将不胜感激!目前,我只是在我的视图中测试它,但当我弄明白它时,我会将它移到我的模型中


谢谢

您需要使用
$query->num\u rows()
。它将返回使用您的查询返回的总行数

例如:

$query = $this->db->query("YOUR QUERY");

    if ($query->num_rows() > 0)
    {
       //DO your stuff
    } 

有关更多参考信息,请参阅

您需要使用
$query->num\u rows()
。它将返回使用您的查询返回的总行数

例如:

$query = $this->db->query("YOUR QUERY");

    if ($query->num_rows() > 0)
    {
       //DO your stuff
    } 
有关更多参考信息,请参阅

试试看

例如:

echo $this->db->count_all_results('my_table');
// Produces an integer, like 25

$this->db->like('title', 'match');
$this->db->from('my_table');
echo $this->db->count_all_results();
// Produces an integer, like 17 

试一试

例如:

echo $this->db->count_all_results('my_table');
// Produces an integer, like 25

$this->db->like('title', 'match');
$this->db->from('my_table');
echo $this->db->count_all_results();
// Produces an integer, like 17 


尝试
sizeof($query->result())
try
count($query->result())
query->num_rows(),如文档中所述尝试
sizeof($query->result())
try
count($query->result())
query->num rows(),如文档中所述谢谢。我试过玩num_rows,但没能玩到!!不过我现在有了:)谢谢。我试过玩num_rows,但没能玩到!!不过我现在有了:)