2011-04-11 70 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);