What's the best way to run SQL query for each item in an array?
I've got the $array of codes:
Array
(
[0] => 12345
[1] => 12346
[3] => 12347
)
Now I'd like to run the following SQL query for each item in the $array:
SELECT * FROM `TABLE` a WHERE a.`Code` = :code
PHP I've been using:
$results = array();
$statement = $pdo->prepare($sql);
$statement->bindParam(':code', $value);
foreach ($array as $key => $value) {
$statement->execute();
while (($results = $statement->fetch(PDO::FETCH_ASSOC)) !== false) {
echo $results;
}
}