php - adding numbers to a database over time.

Associate
Joined
11 Oct 2008
Posts
268
Hi guys. I'm trying to think of a way to increase the number in a database over time. Its for a resourse section for a game im creating. Similar to lords and knights if anyone has played that on their phones.

At the moment the game refreshes every 30 seconds so I can easily code it to add +1 to the database on every refresh.

But I have no idea how I would make it so the +1 was added say every minute, even when the user was logged out.

I was wondering if someone could suggest some reading material or some function to look up that may help me with this.

I have tried google but not had much luck.

Thanks for any help
 
Thanks. I have done a quick google on cron jobs. So If Im understanding it correctly, I would have a simple bit of code to add+1 to the database, then I would set up a cron job in my hosting control panel to execute the code every minute. Is that correct ?
 
As billysielu is suggesting, just calculate the time between the last time you added 1 to the database and just add the appropriate amount of 1s. So all you'd need to do is add a timestamp to when a 1 is added.
 
I do something similar with increments on one of my tools and as mentioned above, I just use epoch timestamps each time the DB is updated, so I can do easy subtraction to find out how long ago the last update was. Much more reliable than a cron job (which tends to stop running when someone else messes up the crontab).
 
Yep, update when the user comes back to the game or when they do something that requires the updated count.
 
Back
Top Bottom