3raser Posted March 14, 2011 Share Posted March 14, 2011 PLEASE NOTE: I did check the PHP manual, although it was a bit too confusing for beginners with timestamps. I'm creating a simple bank interest system for my PHP game. Say I have a 2% interest in my bank, and I want to run it every 20 minutes. How would I do this? Please provide an example as I'm a bit...too lost. :/ Quote Link to comment https://forums.phpfreaks.com/topic/230574-timestamps/ Share on other sites More sharing options...
RussellReal Posted March 14, 2011 Share Posted March 14, 2011 create a db table, called bank id | user_id | total | last_update make last_update a datetime field, total an integer, user_id integer, and id integer.. set up a cron job to run every minute inside the cron job set it up like: mysql_query("UPDATE bank SET last_update = NOW(), total = total + (total * 0.02) WHERE last_update <= DATE_SUB(NOW(), INTERVAL 20 MINUTE)"); Quote Link to comment https://forums.phpfreaks.com/topic/230574-timestamps/#findComment-1187254 Share on other sites More sharing options...
3raser Posted March 14, 2011 Author Share Posted March 14, 2011 create a db table, called bank id | user_id | total | last_update make last_update a datetime field, total an integer, user_id integer, and id integer.. set up a cron job to run every minute inside the cron job set it up like: mysql_query("UPDATE bank SET last_update = NOW(), total = total + (total * 0.02) WHERE last_update <= DATE_SUB(NOW(), INTERVAL 20 MINUTE)"); Thank you! Much appreciated....will take a while to remember something like that. >.< Quote Link to comment https://forums.phpfreaks.com/topic/230574-timestamps/#findComment-1187260 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.