Since Cups has asked, Here's how i would do it. the way the OP came up with works just as well.
The Query string itself, before it's Prepared, -is just a string-. So standard PHP foolery will work on it;
PHP Code:
$query = "SELECT name FROM product WHERE id IN(".implode(',',array_fill(0,count($productid),'?')).")";
$pdo = $db->prepare($query);
Will get you your query string.
Now, because we're using ?'s instead of named ID's, and we have no preceding question marks (that part is very important), we can supply a numerically indexed array to fill the question marks when we bind to PDO....
PHP Code:
$bind = 1; //NOTE: Binding ?'s begins at index 1, NOT 0.
foreach($productid AS $pid) {
$pdo->bindValue($bind,$pid);
$bind++;
}
if we DID have preceding question marks, we would have to take that into account with the value of $bind.
Bookmarks