Rihoj Posted November 10, 2007 Share Posted November 10, 2007 Hello, I consider myself somewhat new to php. I understand most of it, but I usually just have to play around with it, instead of code it straight like i can html and css. So here is my problem. I want to have a site that will update a value according to what time it is, so like everyday at noon a number is increased. My site is set up so that when a user logs in they see how much money they have, and I want that every 24 hours that number is increased for each person by a certain amount. I am not sure how I should go about doing this though? Cause I want to to change for all the users weather they are logged in or not. Link to comment https://forums.phpfreaks.com/topic/76765-time-interval-help/ Share on other sites More sharing options...
Rihoj Posted November 10, 2007 Author Share Posted November 10, 2007 Can anyone help me? I really need this as soon as possible. Link to comment https://forums.phpfreaks.com/topic/76765-time-interval-help/#findComment-388670 Share on other sites More sharing options...
Rihoj Posted November 10, 2007 Author Share Posted November 10, 2007 I thought I had it figured out, but I can not manage to get it to work right. Here is what I have so far $avvy = "SELECT * FROM phpbb_dseusers WHERE user_id =" . $user->data['user_id']; $result = mysql_query($avvy) or die (mysql_error()); while($row = mysql_fetch_array($result)) { $link = $row['user_avatar']; $width = $row['user_avatar_width']; $height = $row['user_avatar_height']; $ship = $row['user_ship']; $money = $row['user_money']; $time = $user->data['user_lastvisit']; $system = gettimeofday(); $interval = (60); } if($time+$interval == $system[sec]) {$time = $system; $money = $money+10; $user->data['user_money'] = $money; } the other variables are for other things Link to comment https://forums.phpfreaks.com/topic/76765-time-interval-help/#findComment-388732 Share on other sites More sharing options...
Rihoj Posted November 11, 2007 Author Share Posted November 11, 2007 Is what I want impossible? Cause no one is replying. Link to comment https://forums.phpfreaks.com/topic/76765-time-interval-help/#findComment-389092 Share on other sites More sharing options...
only one Posted November 11, 2007 Share Posted November 11, 2007 It isn't impossible, there are more than one ways of doing it. The easiest would be to use crontab. Link to comment https://forums.phpfreaks.com/topic/76765-time-interval-help/#findComment-389131 Share on other sites More sharing options...
marcus Posted November 11, 2007 Share Posted November 11, 2007 You could always have a field in a database, that basically lets YOU know if the user has collected their gained money within the pass 24 hours. Then use time() and check the difference between the time last collected. So we can do something like this: <?php $sql = "SELECT * FROM `phpbb_dseusers` WHERE `user_id` = " . $user->date['user_id']; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($res)){ # do other things we'll do time $time = time(); $last = $row['last_collected']; # you might have to add this into your database $day = 3600*24; $total = $time-$last; $collection = $row['collected']; if($collection == '0'){ # give points for first time # update last_collected field with time(); # update collected with the number 1 }else { if($total >= $day){ # give points # update last_collected field with time(); } } } ?> Link to comment https://forums.phpfreaks.com/topic/76765-time-interval-help/#findComment-389135 Share on other sites More sharing options...
Rihoj Posted November 11, 2007 Author Share Posted November 11, 2007 Could you please explain that code a little more? like where I add in what I need to? And what I add in? please and thank you. Link to comment https://forums.phpfreaks.com/topic/76765-time-interval-help/#findComment-389289 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.