Page 1 of 1

Using time with php and mysql

Posted: Mon Mar 21, 2011 7:59 pm
by Baseball435
hey everyone, well i wanted to make a game that uses time like for example every 24 hours if this person owns a store, they get paid 125 gold. How would you implement this? thanks guys!

~baseball435

Re: Using time with php and mysql

Posted: Mon Mar 21, 2011 8:53 pm
by SpiritWebb
Moved to the correct area.

Re: Using time with php and mysql

Posted: Mon Mar 21, 2011 11:25 pm
by PaxBritannia
Use a cron or alternative to run a script that checks for whoever owns a store every 24 hours and give them the gold.

pax.

Re: Using time with php and mysql

Posted: Tue Mar 22, 2011 2:26 am
by Callan S.
Yeah, I'd store time() in some part of the database and then whenever a player logs in, it checks if a day or more has passed since the last storage of time(). If so count the number of days that have passed and go through the database with a while statement, adding gold to those with stores.

Or use a cron. I'm not familiar with them so I dunno.

Re: Using time with php and mysql

Posted: Tue Mar 22, 2011 2:35 am
by Jackolantern
If you are actually looking for the ways to actually evaluate and deal with time calculations, I suggest to read this page of the PHP manual. It is mildly helpful, but there are a lot of good comments down the page. The very first comment has a working script for doing calculations to compare the current time with an existing timestamp.