0

I have the following query

<?php  
$returnedproducts = explode(',',$result['Product']);  
$get = $db->prepare("SELECT * FROM Products WHERE Id IN (' . implode(",", :returned) . ')'");
$get->bindParam(':returned', $returnedproducts);
$get->execute(); 
$results = $get ->fetchAll(); 
?>

Product in the database is stored like 1,2,3,4

However I am getting an error PDO::prepare() expects parameter 2 to be array

How can I adapt my returned variable products to achieve this

Buy Naural
  • 11
  • 4
  • 1
    Well start by echoing the SQL that you are building to see what the error is – RiggsFolly Jan 21 '17 at 21:13
  • 1
    this is a simple issue with wrong quotes. `implode()` is a php function, but due to the quote mix match, it is being treated as a string. – Sean Jan 21 '17 at 21:16
  • You are only binding one value. You also need to use unique placeholders. Implode with `?`s and just pass the `$returnedproducts` to the `execute`. – chris85 Jan 21 '17 at 21:18

0 Answers0