I have a text based RPG and there are ways on the site to temporarily raise your stats. For example I am making a way to have it so that after you drink a potion all your stats but strength goes down by 5 and your strength goes up by 5. Then for each hour the number goes down by 1 so after one hour your stats are down by 4 and strength is up by 4, then after two hours -3 and +3 etc etc until all your stats are at normal.
So the table in my database that holds the stats is called stats and it has 8 columns in it:
id
username
str
dex
con
cha
intel
wis
The other table which holds all the time you drunk the potion is called drunk and it has these columns in it:
id
username
dateline
Where dateline is where you last drunk the potion.
When the user drinks a potion there is a mysql query that goes like this:
mysql_query("UPDATE stats SET str=str+5, dex=dex-5, con=con-5, cha=cha-5, intel=intel-5, wis=wis-5 WHERE username = '$username'") or die(mysql_error());
And in the file that is on every page I have this code. This is the code that will reduce the stats slowly back to normal every hour.
$all2 = mysql_query("SELECT * FROM stats WHERE dateline > " . time() . " - 18000") or die(mysql_error());
while ($all = mysql_fetch_object($all2)) {
}
This is where I am stuck, I do not know how I can get it to do this mysql_query once an hour so that it properly brings up the stats of the user back to normal.
mysql_query("UPDATE stats SET str=str-1, dex=dex+1, con=con+1, cha=cha+1, intel=intel+1, wis=wis+1 WHERE username = '$all->username'") or die(mysql_error());
Thank you in advance.
Josh