Jump to content

MySQL & PHP Time Questions


lill87

Recommended Posts

Im currently trying to make a online text roleplaying game, and im having trouble making a script, ill try to explain it.

 

I want a user to gain 5 "Energy" each 10 minutes, even when the user is not logged in. Now how do i make that in MySQL / PHP? Ive tried many things but cant figure it out, and i cant find any tutorial about it.

 

And how do i make a IF sentence with time? example. ANY time after 30th of october 2008, "something happens".

 

I cant do like:

 

Code:

 

if (X > 30-10-08)
{
thinghappens();
}

 

 

So how do i make it? please help, I would be VERY grateful!

 

Thanks // lill87

Link to comment
https://forums.phpfreaks.com/topic/74814-mysql-php-time-questions/
Share on other sites

Check out these two functions: now() and time(). They should help you time-wise.

 

As for the "energy" question, just do either one of two things:

Can you use cron jobs?

If so, let me know. If not, use the second option:

Update manually

 

$curr_time = time();
$check_time = mysql_query("SELECT `last_update` FROM `time` LIMIT 1");
$diff = $curr_time - $check_time;
if($diff >= (60*10)){//60 seconds times 10 minutes, if true, past 10 minutes
$query = mysql_query("UPDATE `users` SET energy = energy+5");
$query = mysql_query("UPDATE `time` SET last_update = '{$curr_time}' ");
} else {//not past 10 minutes, just do nothing
//lalalalalala
}

Ah thanks, gonna try the cron job tomorrow :D

 

What about the comparing of 2 times, to make a IF statement check if a time is over the limited time.

For instance, a user gets a month premium account, a month later he wont be able to use the service.

 

I cant use:

if ($expiretime > 20071030) { endprem(); }

 

I just cant figure out a logical way of expressing it, but if you know what i mean, please help with this one!

 

Thanks for all the replies :)

 

 

Archived

This topic is now archived and is closed to further replies.

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