Php 将select count()MySQL查询转换为Codeigniter查询
这是我的疑问:Php 将select count()MySQL查询转换为Codeigniter查询,php,codeigniter,mysqli,codeigniter-3,Php,Codeigniter,Mysqli,Codeigniter 3,这是我的疑问: SELECT COUNT(*) FROM `job_progress` WHERE status='Runing' 帮助我:我知道SQL命令,请帮助我获取Codeigniter命令。希望这对您有所帮助: 您可以使用count\u all\u results对具有where条件的数据进行计数 只需运行以下查询: $this->db->where('status','Runing'); return $this->db->count_all_results(
SELECT COUNT(*) FROM `job_progress` WHERE status='Runing'
帮助我:我知道SQL命令,请帮助我获取Codeigniter命令。希望这对您有所帮助: 您可以使用
count\u all\u results
对具有where
条件的数据进行计数
只需运行以下查询:
$this->db->where('status','Runing');
return $this->db->count_all_results('job_progress');
在模型中,添加以下方法来计算所有记录
public function get_count()
{
$this->db->where('status','Runing');
return $this->db->count_all_results('job_progress');
}
在控制器中:
确保已加载包含此方法的模型
更多信息:只需使用
$this->db->select('count(*)->from('job_progress')->where('status','Running')->get()->row()代码>
要了解如何构建codeigniter查询,请阅读codeigniter查询生成器文档:您到底在寻找什么?请始终对答案做出回应,给出一些评论,或者,如果有帮助,将其标记为绿色并向上投票,这是感谢所有程序员的最佳方式
$count = $this->model_name->get_count();
echo $count;