Recently viewed products - how do u do it?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Recently viewed products - how do u do it?

Post by simonmlewis »

Hi

I created a db table to store up to 5 products a person has visited.
However, because this particular web site gets a vast amount of viewings, the db table gather over 240,000 entry rows.

It stores them by their IP Address. So each time a product page is loaded, it looks for their IPs, and then deletes the oldest one and adds the latest. But looking for 5 IPs in 240,000+ rows is very time consuming.

And then on each page it looks for those 5 IPs and shows them on a page to show those 5 products.

It slowed the web site down BIG TIME.

Is there a better way to do this?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
zyntrax
Forum Commoner
Posts: 32
Joined: Wed Apr 13, 2011 2:23 am
Location: Sweden

Re: Recently viewed products - how do u do it?

Post by zyntrax »

Have you tried changing so that it creates 1 row per product and store all ips on the same row?
User avatar
Kastor
Forum Newbie
Posts: 24
Joined: Thu May 01, 2008 2:29 am
Location: Grodno, Belarus
Contact:

Re: Recently viewed products - how do u do it?

Post by Kastor »

Store them in cookie on client side
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Recently viewed products - how do u do it?

Post by flying_circus »

simonmlewis wrote:Is there a better way to do this?
We would have to see some of your code to give you good advice but you should be able to pull all that information, rather quickly, with a single query. A better way to index the results might be based either on user account (if your system has them) or session id.
kevrelland
Forum Commoner
Posts: 73
Joined: Mon Jan 08, 2007 7:41 am

Re: Recently viewed products - how do u do it?

Post by kevrelland »

Kastor wrote:Store them in cookie on client side
yea agree cookie on the client side the easiest
Post Reply