Hi everyone,
I am currently in the process of making some upgrades to a CMS and website that somebody else built. I understand PHP moderately well, but I don’t do OOP - which this website is - so it’s been a bit struggletown. I’ve managed to make most of the changes I want, but there’s one particular bit I just can’t figure out.
Basically, the website is a catalogue sort of thing which gets a list of products from a database (Page A, using function A), and when the user clicks on a product, gets further details about the product (Page B, using function B), also from the database. It’s pretty straightforward stuff.
Now, what I want to do is display a list of the 5 most recently viewed items, on both Page A and Page B. My idea of how to do this was to use sessions and an array, with array_push and array_shift to keep track of the product IDs as the user clicks on more products. I would then use this array in a function (function C) that outputs the thumbnails and stock number of the recently viewed products.
My problem is, I need to get the product ID into the array in function B, and then use the array in function C - and I just can’t seem to make this happen, or even work out if it’s possible.
I hope that’s not confusing. I’m just wondering if anyone can tell me whether what I want is possible - or even if it is completely stupid to try and do the recently viewed items in this way.
I don’t have any code that is remotely working, all I was doing was trying to use:
$GLOBALS['recentItems'] = $arrayOfRecentItems;
in function B. To my knowledge, this should output “Array” when I then use:
echo $GLOBALS['recentItems'];
in function C, if it was working - which it’s not.
Thanks in advance for any help!