0

I have for example this query:

SELECT *
FROM example
WHERE (column_1 = 1 OR column_1 = 2)
    AND (column_2 = 12 OR column_2 = 3)

How can I write it on Codeigniter?

I think something like:

$where = column_1 = 1 OR column_1 = 2;
$this->db->where($where);
$where2 = column_2 = 12 OR column_2 = 3;
$this->db->where($where2);

(I need to separate between each AND)

Is this ok? I don't have an idea how I can see the query as string only.

1

2 Answers 2

1

If I got you right, you need something like this:

$this->db->where("(column_1 = 1 OR column_1 = 2) AND (column_2 = 12 OR column_2 = 3)");

Or what are you trying to achieve?

Sign up to request clarification or add additional context in comments.

Comments

0

Use where_in.

$this->db->where_in('column_1', array(1, 2));
$this->db->where_in('column_2', array(2, 13));

It will be easier to read.

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.