I’m tracking articles views by Total, Today, Yesterday, Week, Month and Year, and I want to sort them accordingly
I have a view table tracking each value, with the ID being the article:

When a particular article gets a view, I increment a value to Total, Today, Week, Month, and Year.
So far so good..
but when tomorrow morning comes, what’s the best way to tally up?..
For example: I need to take Yesterday’s Today column and copy to Yesterday column, and if the Week has changed I need to delete all rows in Week (also with month and year accordingly) –
I realize I can make another table that keeps track of which day/wk/mnth/yr it is and compare it with PHP, then making the changes with PHP, but is there a better way that perhaps I’m unaware of? MYSQL caching, cronjobs or something?..
What happens if your site is down for a day? Who fixes the broken progression in your database? What if the update is missed on Sunday, Jan 31? All of your values will be off, and have fun fixing it.
You should only be storing the view counts in one place, and manipulating that data to fit your needs.
The table structure you should have:
To update the viewcount:
And to get your counts:
Or just do each query programmatically for the periods you would like to fetch.