I have an SQL query that takes the following form:
UPDATE foo
SET flag=true
WHERE id=?
I also have a PHP array which has a list of IDs. What is the best way to accomplish this other than with parsing, as follows, ...
foreach($list as $item){
$querycondition = $querycondition . " OR " . $item;
}
... and using the output in the WHERE
clause?
This would achieve the same thing, but probably won't yield much of a speed increase, but looks nicer.
mysql_query("UPDATE foo SET flag=true WHERE id IN (".implode(', ',$list).")");
You should be able to use the IN clause (assuming your database supports it):
UPDATE foo
SET flag=true
WHERE id in (1, 2, 3, 5, 6)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With