2011-04-11 73 views

回答

1
$this->db->select('COUNT(id) AS c'); 
    $this->db->from('products'); 
    $this->db->where('valid =', 1); 
    $this->db->where('sticky =', 2); 
    $query= $this->db->get(); 
2
$this->db->select('count("id") as c'); 
$this->db->where('valid',1); 
$this->db->where('sticky',2); 
$result = $this->db->get('products'); 
0

我知道這是一個遲到的回答,但個人使用框架的時候,我想建立報表通用越好。我絕對喜歡將查詢中的條件數組傳遞給查詢的能力,再加上我喜歡使用get_where,所以...我提交這個是因爲我的答案略有不同,我覺得使用複雜的框架;]。

$where['valid'] = 1; 
$where['sticky'] = 2; 

$db->select('count("id") as c'); 
$query = $db->get_where('products',$where);