Jump to content

Timestamps?


3raser

Recommended Posts

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. :/

Link to comment
Share on other sites

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)");

 

Link to comment
Share on other sites

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. >.<

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.