Danny620 Posted August 15, 2009 Share Posted August 15, 2009 this should check how many hours the user as missed and credit them with moeny but the thing is when it puts the new update time in it stores it as <?php session_start(); require('mysqli_connect.php'); $id = $_SESSION['id']; // Query the database: $q = "SELECT * FROM test WHERE id='$id'"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); $user = mysqli_fetch_array ($r, MYSQLI_ASSOC); mysqli_free_result($r); //money amount to add for each round $add_money = 1000; //time now, and round time in seconds (1h=60*60seconds=3600) $time_now = time(); $round = 3600; //time of last update+time needed must be smaller then time now to update if (($user[lastupdate]+$round) <= $time_now) { //see how many rounds (hours) were there from last update $nr_rounds = floor(($time_now-$user[lastupdate])/$round); //calculate how much money user gained $all_money = $nr_rounds * $add_money; //calculate how many rounds in seconds (how many hours in seconds) $add_time = $nr_rounds * $round; //lets update users table $q = "UPDATE test SET lastupdate=lastupdate+'$add_time', money=money+'$all_money' WHERE id = '$user[id]'"; $r = mysqli_query($dbc, $q); //here you can refresh page (so you can see progress) or select user again using login } ?> lastupdate 0000-00-00 00:00:00 it should be at date and time not that Quote Link to comment https://forums.phpfreaks.com/topic/170408-datetime-error/ Share on other sites More sharing options...
waynew Posted August 15, 2009 Share Posted August 15, 2009 You're adding dates? Quote Link to comment https://forums.phpfreaks.com/topic/170408-datetime-error/#findComment-898931 Share on other sites More sharing options...
ignace Posted August 15, 2009 Share Posted August 15, 2009 $round = 3600;// in seconds $lastupdate = strtotime($user['lastupdate']); $diff = $time - $lastupdate; $totalhours = $diff / $round; $all_money = $totalhours * $add_money; UPDATE test SET lastupdate = now(), money = money + $all_money WHERE id = '$id' Quote Link to comment https://forums.phpfreaks.com/topic/170408-datetime-error/#findComment-898968 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.