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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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(); } } } ?> Quote Link to comment 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. Quote Link to comment 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.