The code maybe correct but I cannot get it to do want I want.
I can use a variable in a session to filter recordset no problem. However it only displays one product at a time.
I want it so every time a product is viewed on a details page the product id is stored in a variable. Repeated in a repeat table. This table to show maximum of 10 viewed items. If nothing in table displays "No recently viewed items".
I tried to explain more below, code maybe wrong but you should get an idea where I am heading with this.
User clicks detail page of an item
---------------------------------------------------
<a href=" proDETAIL.php?recordID=34>Dress</a>
Page retrieves product id from url parameter
---------------------------------------------------
$_GET('recordID');
Set product id to session named "recentlyViewedItem" (recordset uses to filter db, HOWEVER THIS IS ONLY ONE ID)
---------------------------------------------------
$_GET('recordID') = $_SESSION["recentlyViewedItem"];
set session variable to easier name to work with
---------------------------------------------------
$_SESSION["recentlyViewedItem"] = $rvItem
That variable needs to be checked to see if it already exist in an array of some kind
(perhaps 10 items to display at any onetime, code for array should be on page or coded on page to check MySql database for exact match, I do not know code to do this)
If ($rvItem in array): Ignore/die
If ($rvItem not in array) AND (all array positions have a value in it) : Delete oldest key/value in array then add $rvItem.
Elseif($rvItem if not in array) AND ( array values are not full) : put $rvItem in array And push other values down in array.
i tried to get recordset to read a test array I created of product ids so products could be viewed in a repeat table.
e.g $_SESSION["recentlyViewedItem"] = array(2,36,54,4)
But this did not work.
After some reading around there seems to be different ways to achieve this
sessions, cookies, using MySql database.
However it appears to be in bits and pieces to me and I am still unclear exactly how to achieve this.
Any ideas?