Renlok Posted March 31, 2007 Share Posted March 31, 2007 ive run a game or atleast im setting one up and ive got something where a user will gain a random amount of points every 6 hours, i cant get this to work either they always get the random points whenever they want or they never can get them. ive no clue what the problem is. thanks in advance for any help the code is: $limit1 = 21600; //check user can play $limit = time() - $limit1; $run = mysql_query("SELECT * FROM gameplay WHERE userid='$userid' AND lastplay < '$limit' AND gameid='1'"); $check = mysql_num_rows($run); // End Check $points = $row['points']; $userid = $row['id']; echo "<p align=center>Random points</p>"; if($check == 0) { $random = rand(1,1500); $newpoints = $points+$random; //update user points $sql = "UPDATE users SET points='$newpoints' WHERE id = '$userid'"; $run = mysql_query($sql) or die($sql.mysql_error()); //update last played $run = mysql_query("SELECT * FROM gameplay WHERE userid='$userid' AND gameid='1'"); $check = mysql_num_rows($run); $time = time(); //if entry for this user already exists if($check == '1') { $sql = "UPDATE gameplay SET lastplay='$time' WHERE userid='$userid' AND gameid='1'"; } else { $sql = "INSERT INTO gameplay (userid, lastplay, gameid) VALUES ('$userid', '$time', '1')"; } $run = mysql_query($sql) or die($sql.mysql_error()); echo "<p align=center>You recive $random points from the random points collection dont forget to come back in 6 hours to play again</p>"; } else { echo "<p align=center><b>You cannot play right now, as you last played within 6 hours ago</b></p><p align=center><a href=\"http://www.roeonline.co.uk/arcade.php\">back to games</a></p>"; } Link to comment https://forums.phpfreaks.com/topic/45083-solved-sql-help/ Share on other sites More sharing options...
Renlok Posted April 1, 2007 Author Share Posted April 1, 2007 :-\ Link to comment https://forums.phpfreaks.com/topic/45083-solved-sql-help/#findComment-219033 Share on other sites More sharing options...
Barand Posted April 1, 2007 Share Posted April 1, 2007 Shouldn't that first query have ...AND lastplay > '$limit' .... to find if there are any records within the last 6 hours? And you seem to have variables called "$check" scattered about the code for different checks Link to comment https://forums.phpfreaks.com/topic/45083-solved-sql-help/#findComment-219044 Share on other sites More sharing options...
Renlok Posted April 1, 2007 Author Share Posted April 1, 2007 ok fixed now thanks ^-^ Link to comment https://forums.phpfreaks.com/topic/45083-solved-sql-help/#findComment-219048 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.