how to store previous 7 days data in db?
I want to create simple kind of stats for a page. How can I store the number of hits of last 7 days in the database? I just need an idea about how to store only previous 7 days data in the database. Something like:
- February3: 10
- February2: 11
- Febraury1: 10
- January31: 1
and so on?
Do I need to make开发者_如何学运维 like 7 columns to store each days hits number or I can manage with one column?
I'd suggest you add another table
- pageID - foreign key to your page table (or some other reference)
- date
- hits
and store one row per page per day. You can then delete all rows from this table where date is > 7 days old as a daily job.
I think it would be easier to just store every visit to your database and select the COUNT() of the last 7 days.
Or you could make an extra table that has 1 row for every day and just select the last 7 days with INTERVAL() function.
精彩评论