Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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 将select count()MySQL查询转换为Codeigniter查询_Php_Codeigniter_Mysqli_Codeigniter 3 - Fatal编程技术网

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;