I am having an issue when trying to present some information coming from an array.
I have a foreach that checks the n sessions in my site, then I call the database for each session and load an array of items.
After coming out of the foreach, I would like to use the same array sequentially to show the items one by one again, however I am only seeing the last of the items n times.
Essentially, in the second foreach, the $row2['name'] and $row2['price'] are only showing n number of times but always the last item of the table.
foreach ($_SESSION['cart'] as $item) { $pid = $item['itemId']; $q = $item['qty']; if($q==0) continue; $query2 = $con -> prepare("SELECT * FROM item_descr WHERE id_item = :idItem"); $query2-> bindValue (':idItem',$pid); $query2->execute(); $row2 = $query2->fetch(PDO::FETCH_ASSOC); SOME HTML STUFF.... } SOME INDEPENDENT HTML STUFF HERE:
foreach ($_SESSION['cart'] as $item) { $pid = $item['itemId']; $q = $item['qty']; HTML <div class="subTotalItem"> <span class='cartItemsText'><?php echo **$row2['name']**; ?></span> <span class='cartItemsText2'><?php echo $q." x "." $".$**row2['price'];** $subTotal+= $row2['price'] * $q; ?></span> </div> } Any idea of where the issue might be?