Search code examples
phpmysqlimedoo

Medoo delete ID found in array


I have scripts provided by another coder that use Medoo for database functions. I have a script to delete one item at a time but now I need to delete multiple rows according to a list submitted from checkboxes. For example:

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

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

Unfortunately the documentation and examples provided for Medoo are sparse and do not cover IN examples. So I am looking for suggestions.


Solution

  • $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
        ]
    ]);
    }