Is there a way to put this in one, or multiple FAST queries?:
I’m using PDO::MySQL
<?php
$ids = array(1, 3, 4, 5, 6, 7, 23, 24, 26, 28); // example, this can hold up to 1000 unique id's
$results = array();
$stmt = $pdo->prepare("SELECT a, b, c FROM table WHERE id = ?");
foreach($ids as $id) {
$stmt->execute(array($id));
$results[] = $stmt->fetch(PDO::FETCH_ASSOC);
}
?>
Do I really have to loop the ID’s and with that extending the base query so it shows as:
SELECT a, b, c, FROM table WHERE id = ? OR id = ? OR id = ? //etc
No, you don’t need to loop. The quick and dirty solution is this:
The recommended solution, however, is to load your IDs into a MySQL table, and then do a query with a JOIN.