how to make this sql statment in codeigniter framework php?
how to make this sql statment in codeigniter framework php??
SELECT COUNT(`id`) AS `c` FROM `products` WHERE `valid` = 1 A开发者_C百科ND `sticky` = 2
how to make it in the model
like this way
$this->db->get('products');
how to do that?
$this->db->select('count("id") as c');
$this->db->where('valid',1);
$this->db->where('sticky',2);
$result = $this->db->get('products');
$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();
I know this is a late answer, but personally when using the framework, I like to build statements as general purpose as possible. I absolutely love the ability to pass an array of conditions as the where in the query, plus I like using get_where, so... I'm submitting this because my answer's slightly different and I feel is more invasive into using the intricacies of the framework ;].
$where['valid'] = 1;
$where['sticky'] = 2;
$db->select('count("id") as c');
$query = $db->get_where('products',$where);
精彩评论