0
SELECT COUNT(*) AS  numrows 
FROM (books)
WHERE (
    id_status =1
    OR id_status =2
)
AND  company =2

How can this be converted to CI Active Record?

2 Answers 2

1
$this->db->select('count(*) as numrows')->from('books ')->where("(id_status='1' OR id_status='2') and company ='2'")
Sign up to request clarification or add additional context in comments.

1 Comment

If the result is enough can use count_all_results instead of select and can split where into two parts.
0

Your SQL is elegantly achieved with just three method calls. The returned value will be an int type value (not an object with a num_rows property).

return $this->db
    ->where('company', 2)
    ->where_in('id_status', [1, 2])
    ->count_all_results('books');

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.