Resetting record on month end/start

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
leon_nerd
Forum Commoner
Posts: 25
Joined: Tue Aug 21, 2007 1:20 pm

Resetting record on month end/start

Post by leon_nerd »

I am working on a PHP application. It involves a database table which maintains some candidates and user votes for each of them. Now what I want is at the end of each month or starting of the month, I want the "votes" field in the table to be reseted to zero (0). Now, I am not able to decide how to achieve this. Should I write a php script on the homepage to check if the current day is 1st day of the month. If yes, then I can reset the votes else leave it. The downside of this logic is what if the site is not opened on the 1st day of the month at all, though it is a near impossible case. Can there be a better approach to solve this issue?

Thanks.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Resetting record on month end/start

Post by Christopher »

You should probably not have a "'votes' field in the table". You should probably have a separate table where each record contains the voterID, vote and timestamp. Then to tally votes you select records between the first and last day of the month in question.
(#10850)
Post Reply