2 回答
TA貢獻(xiàn)2080條經(jīng)驗(yàn) 獲得超4個(gè)贊
無(wú)需在代碼的第一行給出 'status' 列,只需使用 '$this->db->select('COUNT(*) as total');' 在第一行并使用帶有狀態(tài)列的 where 子句而不是在“group_by”子句中使用的“status”列。你可以試試下面的代碼:
public function count_rows($status)
{
$this->db->select('COUNT(*) as total');
$this->db->from('shopowner');
$this->db->where('status', $status);
$this->db->group_by('status');
$this->db->get();
}
TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超8個(gè)贊
如果您想在一個(gè)查詢中獲取所有統(tǒng)計(jì)信息,您可以使用以下代碼
$this->db->select('status, COUNT(status) as total');
$this->db->group_by('status');
$this->db->get('shopowner');
但是,如果您想獲得特定的狀態(tài)計(jì)數(shù),則必須將狀態(tài)代碼添加到 where 參數(shù)中
$this->db->where(['status' => $status]);
$result = $this->db->get('shopowner');
echo $result->num_rows();
我希望這會(huì)幫助你)
private function count_rows($status) {
$this->db->where(['status' => $status]);
return $this->db->get('shopowner')->num_rows();
}
在您的控制器中
$data = [
'pending_approval' => $this->count_rows(4),
'approved' => $this->count_rows(2),
'rejected' => $this->count_rows(1)
];
$this->load->view('your_view', $data);
您可以使用<?=$approved?>調(diào)用 $data 項(xiàng)
- 2 回答
- 0 關(guān)注
- 149 瀏覽
添加回答
舉報(bào)
