tcj
tcj

Reputation: 621

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:

and so on?

Do I need to make like 7 columns to store each days hits number or I can manage with one column?

Upvotes: 1

Views: 342

Answers (2)

gnur
gnur

Reputation: 4733

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.

Upvotes: 1

Rup
Rup

Reputation: 34408

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.

Upvotes: 1

Related Questions