I\'m frequently facing this issue, as an Oracle user, playing around with MySql.
Be the following situation:
Here is one way to do this using one query. It won't be the prettiest-formatted query, but it will be just one.
<?php
$id_list = implode(',', $ids);
$whens = implode(
"\n ",
array_map(
function ($id, $value) {
return "WHEN {$id} THEN {$value}";
},
$ids,
$values
)
);
$sql = "
UPDATE value
SET value = CASE id
{$whens}
END
WHERE id IN ({$id_list})
";
?>
See my modified SQLFiddle.