close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

outputting cookie array of IDs

Thread began 3/06/2016 3:36 pm by Christopher West | Last modified 3/23/2016 2:56 pm by Christopher West | 946 views | 18 replies

Christopher WestCommunity Expert

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.

php:
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
?>



php:
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);
}
?>

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...