Using time with php and mysql

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
Baseball435
Posts: 548
Joined: Sun May 30, 2010 3:49 am

Using time with php and mysql

Post 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
User avatar
SpiritWebb
Posts: 3107
Joined: Sun Jul 12, 2009 11:25 pm

Re: Using time with php and mysql

Post by SpiritWebb »

Moved to the correct area.
Image

Image
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: Using time with php and mysql

Post 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.
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: Using time with php and mysql

Post 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.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Using time with php and mysql

Post 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.
The indelible lord of tl;dr
Post Reply

Return to “Advanced Help and Support”