[eluser]Teks[/eluser]
I think I understood correctly - but maybe I did not explain myself too well.
Let's say that you have a site, where you sell SPROCKETS. You store information on each different type of sprocket, in a database, in a table called 'sprockets'. That table has fields to store sprocket size, colour, model number, and everything else you need.
Now, you want to find out which are the MOST OFTEN VISITED sprocket pages. Not only that: you wish to find out which ones are the most visited, on a *daily* basis - that is: which sprocket was most often visited TODAY. This means that today, sprocket A might be the most popular, but tomorrow, sprocket Z may be the favourite.
There are, of course, many different solutions for this. The one that first came to my mind was as follows:
1) in your 'sprockets' table, add a DATE field called "last_visited"
2) then, add an UNSIGNED INTEGER field called "visit_count"
Now, if you are using CodeIgniter, you would already have a 'sprocket controller' that is receiving the requests to display a 'sprocket page'. This controller, most likely, gets the 'sprocket model' to retrieve the information from the database, then sends the information to the 'sprocket view'. Right?
3) in your 'sprocket model', modify the code that retrieves the sprocket information from the database, so that on every sprocket retrieval it also does the following, using your new database fields:
- if 'last_visited' is [TODAY], then add 1 to 'visit_count'
- if 'last_visited' is NOT [TODAY], then put 1 into 'visit_count' and put [TODAY] into 'last_visited'
That's all you have to do.
Now, you have to think a little about the information you are storing. Each 'sprocket' now knows, WHEN (= what date) it was last visited, and HOW MANY VISITS it had on that day. That makes it extremely easy for you to find out what sprocket is the most visited today - this is a simple, single SQL query, which will be something like this:
SELECT * FROM sprockets WHERE last_visited=[TODAY] ORDER BY visit_count DESC LIMIT 1
"[TODAY]" is the DATE value for TODAY, which your model/view/controller scripts should automatically insert when making the query.
There is no need for a cron job, or any extra programming. Every time your view or controller queries the database, it will give you the most visited sprocket, at that precise moment, for that day.
I hope this helps.