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