premierdev99 Posted February 28, 2010 Share Posted February 28, 2010 Hey all... I am working on a little script in Joomla that will allow users to submit 10 articles every 30 days. I have successfully created the part that increments the user's amount of posts after submission and check them before the submission page loads, but I am currently unable to think of a way to get the value to reset every thirty days. I am stumped, but I believe the key lies in the fact that their date of registration is in the database. I'm just new to programming and can't think of how to use this data. Thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/193634-stumped-on-allowing-number-of-actionsmonth/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 28, 2010 Share Posted February 28, 2010 If you record the datetime of submission (with each submission, which you probably already do), rather than attempt to keep a count, you can simply do a query that counts the number of submissions over a datetime range that you pick. Quote Link to comment https://forums.phpfreaks.com/topic/193634-stumped-on-allowing-number-of-actionsmonth/#findComment-1019277 Share on other sites More sharing options...
premierdev99 Posted February 28, 2010 Author Share Posted February 28, 2010 Thanks for the reply... this always seems to happen, but in the time that I was waiting I came up with a great working solution. For posterity's sake, here it is: // Getting Current User ID $user =& JFactory::getUser(); $usr_id = $user->get('id'); // dbg: echo $usr_id; $query = "SELECT * FROM jos_users WHERE id='$usr_id'"; $result = mysql_query($query) or die ("Could not execute query."); $row = mysql_fetch_array($result,MYSQL_ASSOC); extract($row); $strRegDate = strtotime ($registerDate); $strCheckDate = strtotime ($checkdate); $todayDate = date("Y-m-d"); $strTodayDate = strtotime ($todayDate); /* DEBUG CODE $strTodayDate = strtotime("March 28 2010"); echo $strRegDate . '<br />'; echo $todayDate . '<br />'; echo $strTodayDate . '<br />'; echo $strCheckDate . '<br />'; */ // TESTS BEGIN if($strCheckDate == '18000') { // make checkDate in db == regDate + 1 month $tempStrDate = strtotime ( '+1 month' , $strRegDate ) ; $updateDate = date ( 'Y-m-j' , $tempStrDate ); // write it to the database $query_update = "UPDATE jos_users SET checkdate='$updateDate' WHERE id='$usr_id'"; mysql_query($query_update) or die ("Could not execute query."); } else if($strTodayDate > $strCheckDate) { // make checkDate in db == checkDate + 1 month $tempStrDate = strtotime ( '+1 month' , $strCheckDate ) ; $updateDate = date ( 'Y-m-j' , $tempStrDate ); // reset submissions to zero (UPDATE) $query_update = "UPDATE jos_users SET checkdate='$updateDate', submissions='0' WHERE id='$usr_id'"; // write it to the database mysql_query($query_update) or die ("Could not execute query."); // dbg: echo "today was later than checkDate"; // dbg: echo $submissions; } // Defining SQL query for testing submission vs submitlimit $query = "SELECT * FROM jos_users WHERE id='$usr_id'"; // Storing query into result variable $result = mysql_query($query) or die ("Could not execute query."); // Dropping returned data into array $row = mysql_fetch_array($result,MYSQL_ASSOC); // Extracting data into variables that have the same name as the key extract($row); // Performing test if($submissions >= $submitlimit) { die ('Sorry! You are over your quota for submissions this month. Please return to <a href="http://testbed.delabelled.com/">IKIT Home Page.</a>'); } Basically, I made a DATETIME and set it to default as 1970-01-01, which converts to 18000 with strtotime. Then it updates that entry to the registration date plus one month if it is still set to 18000. If today's date is greater than the date of checkDate in the db, it adds another month and stores that value back, and also resets the submission count. I just started PHP yesterday, so this may not be the best method and please criticize as you see fit - I am eager to learn correct coding practice. Quote Link to comment https://forums.phpfreaks.com/topic/193634-stumped-on-allowing-number-of-actionsmonth/#findComment-1019296 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.