Page 1 of 1
Updating User Stats?
Posted: Sat Dec 28, 2002 5:16 am
by Elmseeker
Hi everyone,
I was wondering if anyone mught have any idea as to how to do this. The site I am working on I want to track users usage for their parents, since it is a childrens site. I wish to display to the parents how many times the child has logged on in the past 24 hours, week, month and year. I can store the values in the DB no problem. Where I am running into trouble is trying to figure out how to let the DB know when to reset each of these values to 0, ie 24 hours should be reset to 0 every midnight, weekly at sunday midnight, etc...
Any input would greatly appreciated, Thanks!
Posted: Sat Dec 28, 2002 6:19 am
by qads
you could set up a corn job which rest the stat every night at 1, i am not sure how to set them up though, search the forum, i am sure will find some topics on it.
maybe you could make a history table, which stores a user's stats for a week/day or so, every record you insert into the db, just add a time stamp to it, and make a qurey to check for older records and delete them:
e.g.
Code: Select all
<?php
$time = time();
$older_records = $time - 86400;
$insert = mysql_query("insert to table (f1, f2, timestamp) values ('v1','v2','$time'");
$delete = mysql_query("delete from table where time <=$older_records");
?>
i use this method all the time.
Posted: Sat Dec 28, 2002 7:13 am
by Elmseeker
I don't wnat to actually delete records, I just want to reset the counter to 0 so it would diplay someting like this:
Your child has used the Kidstop site 5 times today, 38 times this week, 186 times this month and 1007 times this year.
Then when midnight (server time rolls around) it would display:
Your child has used the Kidstop site 0 times today, 38 times this week, 186 times this month and 1007 times this year.
And on midnight sunday it would display:
Your child has used the Kidstop site 0 times today, 0 times this week, 186 times this month and 1007 times this year.
The 0's reflect the restting of this value...I have daily, weekly, monthly and yearly fields in the table for logins already...
Posted: Sat Dec 28, 2002 8:37 am
by qads
well then, it is a corn job you need to set up...if you leave your computer on 24/7 then you can set up a task to visit a webpage which resets the stats.....you might wana put a username/password script on it

Posted: Sat Dec 28, 2002 10:23 am
by Gen-ik
It might be worth asking your server provider (the place where your website lives) if they can run php pages every x amount of minutes.
My server provider allows me to run php whenever I want so I have a couple that run by themselves every 10 minutes to update various sites, keep an eye on the MySQL databases, do stuff at certain times of the day, week, or year etc.... it's very handy.
Basically the php pages are just pure php (no html, headers, or echos etc).
Like I said it's worth checking out because having auto-running php scripts can open up a whole new world for you... and you won't have to leave your computer on 24/7 either

Posted: Sat Dec 28, 2002 1:04 pm
by oldtimer
You can do this with the date and time function in PHP but would require constant access to web pages. If the site is not used alot at all hours of the day then set up a cron job.
Another option is that you make a web page for you to visit that would reset the visits that day, if on Sunday(<span style='color:red;text-decoration:blink' title='Alert a moderator!'>grilled spam</span>) then it would also reset the week and if the date was 01 then it would reset month to 0.
Of course you could make a page that refreshes every so many seconds and leave it open to do this as well.
Posted: Sat Dec 28, 2002 3:16 pm
by qads
you gona need ALOT of coffee

Posted: Sat Dec 28, 2002 10:58 pm
by Elmseeker
gads wrote:
you gona need ALOT of coffee
Hehe, Sure does seem that way doesn't it? I do believe the self running php script would be cool and will definately have to get more info on how to do something like that...Thanks for all the input folks!