I don't have any code or database to display, because I am in the planning stage, and I can't figure out the correct way to do this.
I want to determine if a user has performed a specific action each day over the course of a week. If they have I want to perform an action. Each time there is a break in days, I need to reset.
So for example:
Day 1 | task performed 25 times
Day 2 | task performed 13 times
Day 3 | task performed 18 times
Day 4 | task not performed... start over at Day 1.
.....
Day 1 | task performed 3 times
Day 2 | task performed 11 times
Day 3 | task performed 14 times
Day 4 | task performed 7 times
Day 5 | task performed 3 times
Day 6 | task performed 10 times
Day 7 | task performed 23 times
echo 'You have successfully completed 71 tasks consecutively over a period of 7 days';
I guess the real question becomes, what would be the best way to achieve this? Should I try to store 7 cookies based on date, and destroy all existing cookies if the newest cookie value is more than 24 hours old? Should I try setting and updating the date via the database?
Suggestions as potential solutions to achieve this is what I am looking for, keeping in mind this is a very database intensive app I am working on, so the less database calls IMO the better.
UPDATES
So I am trying to plan this out using a database and I am just running into issues at every angle.
If I try to set an incremental column there is no way to tell when the last update was.
If I set a table, its EXTREMELY complicated as I have to base the value off consecutive dates. So I can't do a simple 7 day search, I have to test that each result is within 24 hours of the previous result set in the database, else how would I be able to distinguished someone who completed task on day 1, 3, and 7 vs the one who did it 1, 2, 3, 4, 5, 6, and 7.
Cleaning up the database is equally troublesome. How would I do a cleanup. I can't simply test that the data is within 7 days of the current date because that doesn't account for someone completing tasks on day 5 but not day six... and then on day 7... and equally its complicated because each user will have a different start date. So I may have started tasks today and another user 5 days ago. I can safely assume all dates over 7 days are expired, but that doesn't really help determine breaks in days.
I am so confused how to actually accomplish this task.