0

how to make this sql statment in codeigniter framework php??

SELECT COUNT(`id`) AS `c` FROM `products` WHERE `valid` = 1 AND `sticky` = 2

how to make it in the model

like this way

$this->db->get('products');

how to do that?

3 Answers 3

2
 $this->db->select('count("id") as c');
$this->db->where('valid',1);
$this->db->where('sticky',2);
$result = $this->db->get('products');
Sign up to request clarification or add additional context in comments.

Comments

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();

Comments

0

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.