outputting cookie array of IDs
Hi, a while back I asked about using cookies to display "last viewed products slider"
I almost got it working, however its only displaying 1 cookie. so the problem looks like on the page that sets the cookie (its is overwriting the previously saved cookie) how can I store it all in an array which I can then output on my other pages (also not storing any duplicate IDs)
I think on the product detail page I need to save the product ID into a string array (check so its not a duplicate) and then after save the string array into a cookie. then on the in the recordset that accesses the cookie I need to access the array and output it as a products.
On the page that displays all last viewed products:
<?php
$rsViewedProducts = new WA_MySQLi_RS("rsViewedProducts",$ecartdb,1);
$rsViewedProducts->setQuery("SELECT * FROM products WHERE ProductID = ?");
$rsViewedProducts->bindParam("i", "".(isset($_COOKIE['ViewedProducts'])?$_COOKIE['ViewedProducts']:"") ."", "-1"); //colname
$rsViewedProducts->execute();
?>
<?php
while(!$rsViewedProducts->atEnd()) {
?>
<a href="product.php?Product=<?php echo($rsViewedProducts->getColumnVal("ProductName")); ?>" class="b-link-fade b-animate-go">
<div class="item4"><img src="libra/images/<?php echo($rsViewedProducts->getColumnVal("ProductSKU")); ?>.jpg" alt="" class="responsive-image"></div>
<div class="b-wrapper">
<h2 class="b-from-left b-animate b-delay03"><?php echo($rsViewedProducts->getColumnVal("ProductName")); ?></h2>
<p class="b-from-right b-animate b-delay03">£<?php echo($rsViewedProducts->getColumnVal("ProductPrice")); ?></p>
</div>
</a>
<?php
$rsViewedProducts->moveNext();
}
$rsViewedProducts->moveFirst(); //return RS to first record
?>
on the page that saves a cookie
<?php
$rsProduct = new WA_MySQLi_RS("rsProduct",$ecartdb,1);
$rsProduct->setQuery("SELECT * FROM products WHERE ProductName = ?");
$rsProduct->bindParam("s", "".(isset($_GET['Product'])?$_GET['Product']:"") ."", "-1"); //colname
$rsProduct->execute();?>
<?php
if ("" == "") {
setcookie("ViewedProducts", "".($rsProduct->getColumnVal("ProductID")) ."", time()+(60*60*24*30), "/", "localhost", 0);
}
?>