3

Below is CodeIgniter single column where_in clause $this->db->where_in('x1',$val);

how can I pass multiple column in CodeIgniter where_in clause like below MySQL query:

select *
from tab1
where (col1,col2) in ((1,2),(2,3))`
0

1 Answer 1

2

Assume your data array is like this(should be)

$val1 = array(1,2);
$val2 = array(2,3);

And query should be

$this->db->select('*');
$this->db->from('tab1');
$this->db->where_in('col1',$val1);
$this->db->or_where_in('col2',$val2);
$query = $this->db->get();
$result = $query->result_array();

Or else you can use

$this->db->query("select * from tab1 where (col1,col2) in ($val1,$val2)");
Sign up to request clarification or add additional context in comments.

5 Comments

for example I updated only where col1 = 1 or 2 and col2 = 2 or 3 , but this updated also col1=1 and col2=3
change this and see $this->db->or_where_in('col2',$val2);
$data = array( approve' => 1 ); $this->db->where_in('third_id', $t_id); $this->db->where_in('_id', $s_id); $this->db->update(TAB, $data);
same thing happen for OR also
This query builder script is not identical the raw sql lower in the answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.