Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement row constructor syntax using CodeIgniter's where_in() query building method [duplicate]

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))`
like image 322
Thiyagu Avatar asked Jan 01 '26 17:01

Thiyagu


1 Answers

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)");
like image 180
Abdulla Nilam Avatar answered Jan 03 '26 06:01

Abdulla Nilam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!