当我的列出is_active
现时0
,我想对字段求和并且我想将它显示到我的仪表板页面。如果is_active
是1
它应该跳过而不是求和。
这个怎么做?查询是什么?我有我内置的示例查询CodeIgniter
:
$this->db->select_sum('is_active');
$query = $this->db->get('postfes');
if ($query->num_rows() = 0) {
return $query->num_rows()->is_active;
} else {
return 0;
}
您需要使用where
条件
$this->db->select_sum('is_active'); // the field you want to sum
$this->db->where('is_active', 0)
$data = $this->db->get('postfes')->row();
if ($data) {
return $data->is_active;
} else {
return 0;
}
如果要计算 is_active = 0 的位置,请使用
$this->db->select('count(*) as total'); // the field you want to sum
$this->db->where('is_active', 0)
$data = $this->db->get('postfes')->row();
if ($data) {
return $data->total;
} else {
return 0;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句