如何使用查询从MySQL数据库删除ID

时间:2018-09-28 09:05:10

标签: php mysql wordpress

我正在尝试删除无法使用的SQL上的ID,但我得到了string(87) "DELETE FROM wp_availability WHERE id IN (Array,Array,Array,Array)" 得到这种值

if ( count( $remove ) > 0 ) {
        $removeSQL = "DELETE FROM " . $this->table . "  WHERE `id` IN (" . 
       implode( ",", $remove ) . ")";
       if ( $wpdb->query( $removeSQL ) ) {
      $saved = true;
   }
   }

预先感谢

1 个答案:

答案 0 :(得分:0)

要扩展Vince0789的答案...

$remove看起来包含一个数组数组,而不仅仅是一个id字符串。

例如,$remove的布局可能如下所示;

[
    [ 
         'id' => 1,
         'content' => "Foo"
    ],
    [ 
         'id' => 2,
         'content' => "Bar"
    ],
]

您需要做的是在array_column()数组上使用$remove来捕获数组中的ID,然后内插该新数组并将其传递给查询。

$to_remove = array_column($remove, 'id'); //assuming that id is the column you want

http://php.net/manual/en/function.array-column.php

相关问题