Forum Moderators: open

Message Too Old, No Replies

Reseting a column at the beginning of each month

         

Seamless

5:00 pm on Nov 11, 2005 (gmt 0)

10+ Year Member



I have a simple peice of php code which adds 1 to two columns every time a users profile is visited.

What i would like to do is to reset one of those columns at the beginning of each month. So i will end up with a column for total visits and a column for monthly visits.

I would prefer to do this via the web page rather than a cron job. Any ideas?

My thought was to include a script at the beginning of each page which will check for the date but i don't really know where to start. I hope someone can help me, thanks in advance.

Also not sure if i have posted this in the correct forum it could be in a php forum.

jonrichd

12:17 am on Nov 12, 2005 (gmt 0)

10+ Year Member



Seems to me that there's no way you can do this without storing the date of the user's last visit in the DB somewhere -- what if the user's only visit is on the last day of the month? Should you reset the month's visit count to 1, or leave it as it is?

Assuming that you've got the last visit date (or at least the month and year of the last visit stored with the user), then pcode for what you want to do would be

if (currentmonth > storedmonth and currentyear >= storedyear) or (currentmonth <= storedmonth and currentyear > storedyear) then reset count to 1

I believe this solves your problem, and takes care of the year rollover as well.

jonrichd

12:23 am on Nov 12, 2005 (gmt 0)

10+ Year Member



Sorry, Seamless, but I just noticed that was your first post. Welcome to WebmasterWorld [webmasterworld.com]. I hope you learn (and share) a lot here.

- Jon

Seamless

11:05 pm on Nov 12, 2005 (gmt 0)

10+ Year Member



Sorry, i didn't explain myself very well. It adds a 1 to the column when anyone visits that profile not just the user who's profile it is. Just like a normal counter for that particular webpage.

Seamless

11:06 pm on Nov 12, 2005 (gmt 0)

10+ Year Member



oh and thanks for the welcome :D