$ids = $_POST['ids'];

// sky***earth***sea***sun***...

$ids = explode("***", $ids);

foreach ($ids as $id) {
    $st = $db->query("delete from tags where id = " . $id);
}

Is there a more elegant way to delete multiple rows, especially regarding peformances in case of huge array? Something like:

$st = $db->query("delete from tags where id in " . $ids);

Any suggestion?

up vote 1 down vote accepted

Just replace the exploded *** with a comma(,)

$st = $db->query("delete from tags where id in (" . implode(",", explode("***", $ids)) .")");

Source: https://stackoverflow.com/a/17657893/5837918

$kk= ''; foreach ($ids as $id) { $kk.=$id. ','; } $kk = rtrim($kk, ','); $st = $db->query("delete from tags where id In($kk))";

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.