how to make mysql update automaticly
Moderator: General Moderators
how to make mysql update automaticly
Hey, I am trying to get mysql to reset a certian number in the database after every 24 hours. What I am trying to do is create a hit counter that not only displays the total number of hits but also the hits recieved today. I want this number to reset every 24 hours, but I dont know how. Can anybody here help me? Thanks.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
example:
Code: Select all
$query = mysql_query("SELECT last_hit_time,day_hit_count,hit_count FROM hit_table WHERE 1 LIMIT 1") or die(mysql_error());
list($last_time,$day_count,$count) = mysql_fetch_row($query) or die(mysql_error());
$last_time = explode(":",$last_time);
$last_time = mktime($last_time[0],$last_time[1],$last_time[2],1,1,2000);
$now = mktime(date("H"),date("i"),date("s"),1,1,2000);
if($now < $last_time)
$day_count = 1;
else
$day_count++;
$count++;
$query = mysql_query("UPDATE hit_table SET last_hit_time = NOW(), day_hit_count = '$day_count', hit_count = '$count' LIMIT 1") or die(mysql_error());
if(mysql_affected_rows($query) > 0)
echo "worked";
else
echo "didn't work";