複数の列でCodeIgniterの中に複数の行を削除します。

ローランド:

私は次のように、連想配列を持っています:

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"
  }
}

私は、データベースからこれらの行を削除しようとしているが、私は実行するための正しいCodeIgniterの「クエリを見つけることができません。

生成されたクエリは次のようにする必要があります:

DELETE FROM table
WHERE (userId,customer_id) IN ( (10,1809),(10,1809),(45,210) )

私はこれをしようとした場合

$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()));

私はもちろん、正しいされていない、これを取得します:

DELETE FROM `table`
WHERE (userId, customer_id) IN(Array, Array, Array)
多くのBoominathan:

単一の配列に関連する配列の値を取得し、その後、クエリにpassit

$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()));

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=278375&siteId=1