Roland :
I have an associative array, like:
array(3) {
[0]=>
array(2) {
["userId"]=>
string(1) "10"
["customerId"]=>
string(3) "1809"
}
[1]=>
array(2) {
["userId"]=>
string(1) "13"
["customerId"]=>
string(3) "1094"
}
[2]=>
array(2) {
["userId"]=>
string(1) "45"
["customerId"]=>
string(2) "210"
}
}
I'm trying to delete these rows from database, but I can't find correct Codeigniter' query to run.
The generated query should be like this:
DELETE FROM table
WHERE (userId,customer_id) IN ( (10,1809),(10,1809),(45,210) )
If I try this
$this->db->where_in( '(userId, customer_id)', array( array(10,1809), array(10,1809), array(45,210) ));
$this->db->delete('table');
die(var_dump($this->db->last_query()));
I get this, which is not correct, of course:
DELETE FROM `table`
WHERE (userId, customer_id) IN(Array, Array, Array)
Boominathan Elango :
Get the associated array values into single array then passit into query
$assoicative_array = array(array(10,20,30));
$ids=array();
foreach($assoicative_array as $key =>$value ){
$ids[]=$value;
}
$this->db->where_in('userId',$ids);
$this->db->where_in('customer_id',$ids);
$this->db->delete('table');
die(var_dump($this->db->last_query()));
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=220572&siteId=1