PHP MySql Storing Data for 24 hours


I'm building a toplist for my site and instead of recording in and out hits and emptying the database every 24 hours I would like to record in and out hits "within the last 24 hours", this way the toplist will always look busy no matter what time you look at it, while still acurately ranking sites.

So basically I'll have to add a record to the database logging an 'in' hit (for example) and the remove it around 24 hours later, or simply not consider it when ranking the sites.

I want to know the most efficient way of doing this, I have some ideas but they all seem really resource heavy. I hope you understand what I'm trying to achieve 🙂 Any help would be appreciated.

Best Solution

You don't necessarily have to delete "old" data all the time. You can also limit the data set to records within the last 24 hours when querying data.

  AND hit_datetime > Now()-Interval 24 hour