orignal php code
$sql = "SELECT * FROM products WHERE id IN(";
foreach($_SESSION['cart'] as $id => $value){
$sql .=$id. ",";
}
$sql=substr($sql,0,-1) . ") ORDER BY id ASC";
$query = mysql_query($sql);
$totalprice=0;
$totalqunty=0;
if(!empty($query)){
while($row = mysql_fetch_array($query)){
$quantity=$_SESSION['cart'][$row['id']]['quantity'];
$subtotal= $_SESSION['cart'][$row['id']]
['quantity']*$row['productPrice'];
$totalprice += $subtotal;
$_SESSION['qnty']=$totalqunty+=$quantity;
i tried like this
$sql = $conn->prepare("SELECT * FROM products WHERE id IN(");
foreach($_SESSION['cart'] as $id => $value){
$sql .= $id . ","; }
$sql.=substr($sql,0,-1) . ") ORDER BY id ASC";
$query = $conn->prepare($sql);
$query->execute();
$totalprice=0;
$totalqunty=0;
if(!empty($query)){
while($row = $query->fetch(PDO::FETCH_ASSOC) ){
$quantity=$_SESSION['cart'][$row['id']]['quantity'];
$subtotal= $_SESSION['cart'][$row['id']]
['quantity']*$row['productPrice'];
$totalprice += $subtotal;
$_SESSION['qnty']=$totalqunty+=$quantity;
but this is not working, this is a shopping cart part code.so please can anybody tell me how I can change this code in pdo and what's wrong with my written code in pdo.