kirbyweb Posted November 17, 2009 Author Share Posted November 17, 2009 OK I took the timestamp out on the top part, now the only thing is, when I am logged out, and I log in, it gives them the minutes when they were logged out even when it is at 500, the 500 then becomes like 515 or something.How do I stop this. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 17, 2009 Author Share Posted November 17, 2009 $username = mysql_fetch_array($query);$last = $username['lastupdate']; //timestamp from db$extraTime = time() - $last;$money = floor($extraTime / 60);if ($money<500){if ($money > 0) { //lets update users table mysql_query("UPDATE `castle wars users` SET money=money+$money WHERE id= '$username[id]'") or die(mysql_error());}echo 'user\'s money:'. ((int)$username['money']+(int)$money) .'money.';}else echo 'user\'s money: 500'; //lets update users table mysql_query("UPDATE `castle wars users` SET lastupdate=lastupdate+$extraTime WHERE id= '$username[id]'") or die(mysql_error());?> Yeah now, even when it is 498 it still updates the money. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 17, 2009 Share Posted November 17, 2009 Yeah, look at the if statements. You're telling it to update the money when the money to be added (not the user's money, but the money to add) is between 0 and 500: if ($money<500){if ($money > 0) { You're also not making sure it stops at 500, as long as the money to add is between 0 and 500 you add it. You don't check to see if the money to add plus the current amount would be more than 500. You also always print that the user has 500 without checking what it actually is, the database could say 600 but you're printing that the user has 500. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 17, 2009 Author Share Posted November 17, 2009 So how do I fix it. Link to comment Share on other sites More sharing options...
thescientist Posted November 17, 2009 Share Posted November 17, 2009 why don't you try it? Work out the logic with us if you have to. I understand this may be new to you, but it is basic stuff, and you should really be trying to at least attempt it on your own first. Sometimes it is easier to write out the logic step by step; telling the computer instructions as if you were telling it to a person. Work it out and when you think it makes sense, start converting each line to code. Put a bunch of print statements in your code to track how your code is executing. Maybe that will help. Link to comment Share on other sites More sharing options...
kirbyweb Posted November 17, 2009 Author Share Posted November 17, 2009 Thanks I hope it helps, I fixed it. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.