Hey!
I am having a little problem with a time script. It is using the time() function, but I don't know how to use that function (I didn't create this script. a guy made it for me). The problem is, that the value is not updating in the database(it should update every 12 minutes, or every minute,depending on what i write in a place..) I guess that the fault is in the code somewhere.. but it is not in the queries.. I've tested them.. I can't find anything, but as I said, i don't know how this function works.. so can anyone please try to help me figure out whats wrong in this code:
(And please, don't ask me to sue cronjobs. I don't like them for some reason).
<?php
$multiplier = 1 / 5;
$frequency = 3600 * $multiplier;
$increment = 5 * $multiplier;
$current_time = time(); // get the current server time in second
$last_update_time = mysql_result(mysql_query("SELECT hptime FROM characters"), 0); // This could be anywhere even in a separate text file!
$time_difference = $current_time - $last_update_time;
$hours_passed = $time_difference / $frequency; // convert sec to min then to hours --> 3600 second / 60 = 60 minutes / 60 = 1 hour
$full_hours_passed = floor($hours_passed); // round the number of decimal hours down to the nearest whole hour
$remaining_seconds = $time_difference % $frequency; // number of sec left when time difference is divided by 3600 sec --> 7 % 3 = 1 and 6 % 3 = 0
if($full_hours_passed > 0){
$new_update_time = $current_time + $remaining_seconds;
$hp_increase = $full_hours_passed * $increment;
mysql_query("UPDATE `characters` SET `temphealth` = CASE WHEN `temphealth` + $hp_increase <= `maxhp` THEN `temphealth` + $hp_increase ELSE `maxhp` END WHERE `temphealth` > `maxhp`");
mysql_query("UPDATE characters SET hptime = $new_update_time");
}
?>