lill87 Posted October 25, 2007 Share Posted October 25, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/74814-mysql-php-time-questions/ Share on other sites More sharing options...
kratsg Posted October 26, 2007 Share Posted October 26, 2007 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 } Quote Link to comment https://forums.phpfreaks.com/topic/74814-mysql-php-time-questions/#findComment-378298 Share on other sites More sharing options...
lill87 Posted October 26, 2007 Author Share Posted October 26, 2007 I use Windows XP Professional, does Cron Jobs work on it? And if so, can you link any good Cron job tutorials? Thanks for the reply! Quote Link to comment https://forums.phpfreaks.com/topic/74814-mysql-php-time-questions/#findComment-378303 Share on other sites More sharing options...
kratsg Posted October 26, 2007 Share Posted October 26, 2007 I do cron jobs as they relate with php (IE: cpanel). However, for Windows XP Professional, just do a search for cron jobs+windows xp and see what comes up. Quote Link to comment https://forums.phpfreaks.com/topic/74814-mysql-php-time-questions/#findComment-378308 Share on other sites More sharing options...
lill87 Posted October 26, 2007 Author Share Posted October 26, 2007 Ah thanks, gonna try the cron job tomorrow 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 Quote Link to comment https://forums.phpfreaks.com/topic/74814-mysql-php-time-questions/#findComment-378316 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.