sac0o01 Posted November 3, 2011 Share Posted November 3, 2011 So I have an application that allows users to earn points after logging in and visiting their account page using the following: $addviews = mysql_query("UPDATE users SET viewlimit = viewlimit + 100 WHERE user_id = '".$_SESSION['userId'] . "' "); This works fine except that by simply refreshing the page the user will gain another 100 points, and on and on.... What would be a simple way to only award the points once a day? Quote Link to comment Share on other sites More sharing options...
freelance84 Posted November 3, 2011 Share Posted November 3, 2011 You could add a last updated field, then only update 100pts when the last update field says the previous day. Quote Link to comment Share on other sites More sharing options...
sac0o01 Posted November 3, 2011 Author Share Posted November 3, 2011 Yes, good thinking. Hadn't thought of that. Would be rather simple to do. Actually I had just came up with this: $dailylimit = mysql_query("SELECT lastvisit FROM users WHERE user_id = '{$_SESSION['userId']}' "); $dlrow = mysql_fetch_row($dailylimit); $lastvisitdate = $dlrow[0]; $todaysdate = date("Y-m-d"); if($lastvisitdate != $todaysdate) { $addviews = mysql_query("UPDATE users SET viewlimit = viewlimit + 100 WHERE user_id = '".$_SESSION['userId'] . "' "); } Just have to make sure the code is executed before the query is sent to update "lastvisit" . 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.