First of all, I’m using PDO. I believe it can be done using prepare query, but I have no idea how.
The problem is, I got an array with values, and I need to check, if those values exist in the database.
Right now, it looks like:
foreach( $arr as $id ) {
$match =$PDO->query("SELECT `id` FROM `users` WHERE `id` = " . intval($id))->fetch();
if(isset($match['id']))
//exist
else
//not exist.
}
I don’t wan’t to run this query in every loop to check if the $id exist in the database.
So is there any way, to collect all of those values from foreach, and then run a one query to check if each value exist in the database?
How about this: