Thanks again. It is certainly something to look into. And I will be.
Having no access to the event scheduler, I decided on an alternative method for gaining turns: Requiring the user to manually "accept" them by clicking on a link/button.
What I did was record the last time they clicked the "Harvest" button, which would grant them "turns."
Then everytime they click it again, it will grant them more turns based on how many 5 minute intervals go by.
The tough part was figuring out how not to lose the "remaining" time in between each interval. For this, I chose to round down the Currenttime to the previous 5 minute interval and record it.
The Code I came up with is below: EXTREMELY UGLY! Be warned.
I removed the SQL so the top part might be incorrectly syntaxed.
Code:
<?php
$lastharvest = '2012-02-09 11:54:10'
$strlh = strtotime($lastharvest[0]);
$curdate = date ('Y-m-d H:i:s');
$strcurdate = strtotime ($curdate);
$timediffsec = $strcurdate-$strlh;
$mins = $timediffsec/60;
$turns = floor($mins/5);
echo "Last Harvest: $lastharvest[0]";
echo "<br>Current Date: $curdate";
echo "<br>Last Harvest (unix: $strlh";
echo "<br>Current Date (unix): $strcurdate";
echo "<br>Difference in time (unix): $timediffsec";
echo "<br>Minutes Passed: $mins";
echo "<br>Turns Gained Since Last Harvest: $turns";
}
/* Make '$newturns' Variable to be sent to DB to update tbl 'user_stats'.'turns'*/
$query = "SELECT turns FROM user_stats WHERE user_id='$user_id'";
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
$curturns = mysql_fetch_row($result);
$newturns = $curturns[0]+$turns;
echo "<br><br>Current turns: $curturns[0]";
echo "<br>New Total Turns: $newturns";
if ($newturns > 200) {
$newturns = 200;
}
echo "<br>Total Turns to be Recorded: $newturns";
/* Make new 'curdate' variablo, rounded down to earliest 5 minute intervale */
$rndcurdate = date('i', $strcurdate);
$rndmin = $rndcurdate - ($rndcurdate % 5);
$arrayCurdate = getdate($strcurdate);
echo "<br>arrayUnix: $arrayCurdate[0]";
echo "<br>arrayMinutes: $arrayCurdate[minutes]";
$arrayCurdate[0] = $arrayCurdate[0] - ($arrayCurdate[minutes]*60) + ($rndmin*60);
echo "<br>arrayUnix after math: $arrayCurdate[0]";
$minCurdate = date('Y-m-d H:i:s', $arrayCurdate[0]);
echo "<br>";
echo "<br>Time Rounded Down to lastest Five Minute interval: $rndmin";
echo "<br>Above as array: $arrayCurdate[minutes]";
echo "<br>New Current Time to be Recorded: $minCurdate";
?>
Again, I ask for any advice/criticisms on the code. Better suggestions on how to do it etc.
I'm almost sure there is a better way to record the rounded down currenttime. But I did what I could. Seconds exist..but will be ignored...so I can probably trim them off.