okay ive been pulling my hair out over this; this is for a game; and in the game you have turns; you get 1000 turns every 10 minutes; with a max of 15000 turns; i use sessions so $id is stored in them; heres the code for the turns, but for some reason its not working; i have a timer at the bottom of the page that tells you when the next time you recieve turns will be; thats the date() thing;
$query = "SELECT * from info where id=$id";
$query_result = mysql_query($query);
$row = mysql_fetch_assoc($query_result);
$turns = $row["Turns"];
$stamp = $row["timestamp_last"];
$now = time();
$MinsPerTurn = 10; #Mins Per Turns given
$SecsPerTurn = ($MinsPerTurn 60); # Seconds Per Turns Given
$TurnsPerTime = 1000; #Turns Given At A Time
$MaxTurns = 15000; #Max Turns
$SecsSinceLastTurns = ($now - $stamp); #Calculates Seconds Since Last turns givien
$SetsOfTurnsToAdd = floor($SecsSinceLastTurns / $SecsPerTurn); # Caclucates The number of Sets of turns to add
$TurnsToAdd = ($SetsOfTurnsToAdd $TurnsPerTime);
$dontcare = ($SetsOfTurnsToAdd * $SecsPerTurn);
$LeftOverSecs = floor($SecsSinceLastTurns - $dontcare); # Seconds Left over
If ($LeftOverSecs > 600) { $LeftOverSecs == 0; }
$newturns = ($turns + $TurnsToAdd);
if($newturns > $MaxTurns) { $newturns = $MaxTurns; }
$NewTurnStamp = ($now - $LeftOverSecs);
If ($TurnsToAdd != 0)
{
$query = "UPDATE info SET Turns='$newturns', timestamp_last='$NewTurnStamp' WHERE id='$id'";
mysql_query($query);
}
$time = date("H:i:s", mktime("0,0,$NewTurnStamp"));
thank you ahead of time...