Medoo 删除在数组中找到的 ID

Medoo delete ID found in array

我有另一个使用 Medoo 来实现数据库功能的程序员提供的脚本。我有一个脚本可以一次删除一个项目,但现在我需要根据从复选框提交的列表删除多行。例如:

$delete = "123, 124, 125, 126";

global $db;
$sql = db::query("DELETE FROM users, [id IN '$delete']");

不幸的是,为 Medoo 提供的文档和示例很少,并且没有涵盖 IN 示例。所以我正在寻找建议。

$delete = "123, 124, 125";        // original string

$delete = explode(',',$delete);   // convert to array

foreach($delete as $id) {         // walk wthrough array items

$database->delete("users", [      // run medoo query 
"AND" => [
    "id" => intval($id)          // if whitespaces, make an integer
    ]
]);
}

真的很简单。只需提供一个带有 id 的数组。

$database->delete("users", [
    "id" => [123, 124, 125, 126]
]);

查看medoo删除方法http://medoo.in/api/delete

$database->delete("account", array(
    "id" => array(123, 124, 125, 126)
));

$delete = "123, 124, 125";        

$ids_array= explode(',', $delete);  

foreach($ids_array as $id) {        
 $database->delete("users", array("id" => $id));
}

$ids_array= explode(',', '123, 124, 125'); 

function delete_by_id($value, $key){
  global $database;
  $database->delete("users", array("id" => $value));
}

array_walk($ids_array,"delete_by_id");

或......

$ids_array= explode(',', '123, 124, 125'); 
array_walk($ids_array, function($value, $key) use (&$database){
   $database->delete("users", array("id" => $value));
});

您可以查看上次执行的查询:

echo $database->last_query();