TheEmperor TheEmperor - 1 year ago 84
MySQL Question

How to use where in statement in codeigniter with pair of values from multidimensional array

I have the following array:

$chain_combination = array (array('a','b'), array ('c','d'), array('e','f'));

How I can make the following query in codeigniter by using the $chain_combination array?

FROM table
WHERE (column1, column2) IN (('a', 'b'), ('c', 'd'), ('e','f'))

Answer Source
$arr = array(array('a','b'), array ('c','d'), array('e','f'));

echo "<pre>";

$out = array();
foreach( $arr as $key=>$val ) {
    if( is_array($val) ) {
        $out[] = "('".implode("','",$val)."')";

$final = implode(",",$out);


//out: ('a','b'),('c','d'),('e','f') 

with foreach and implode

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download