brucegre94 Posted March 28, 2011 Share Posted March 28, 2011 I am making a website where someone buys a membership and it updates the expiry date to 30 via mysql, but I cannot figure out how to use cron jobs to run a php script everyday to minus (-) all the expiry dates by 1 every day. Thanks in advance Quote Link to comment Share on other sites More sharing options...
btherl Posted March 28, 2011 Share Posted March 28, 2011 Why do you need to minus the expiry dates by 1 every day? Quote Link to comment Share on other sites More sharing options...
btherl Posted March 28, 2011 Share Posted March 28, 2011 If you're doing what I think you're doing, you should set the expiry date to be today's date + 30 days. Then the account is expired when the current date is after the expiry date. Quote Link to comment Share on other sites More sharing options...
brucegre94 Posted March 28, 2011 Author Share Posted March 28, 2011 Why do you need to minus the expiry dates by 1 every day? So when the expiry date gets to 0 the member will have to keep their standard membership, or by another 30 days of the upgraded membership. Quote Link to comment Share on other sites More sharing options...
brucegre94 Posted March 28, 2011 Author Share Posted March 28, 2011 If you're doing what I think you're doing, you should set the expiry date to be today's date + 30 days. Then the account is expired when the current date is after the expiry date. So date("m/d/y") + 30 ? Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 28, 2011 Share Posted March 28, 2011 If you're doing what I think you're doing, you should set the expiry date to be today's date + 30 days. Then the account is expired when the current date is after the expiry date. So date("m/d/y") + 30 ? There is an easier way. When creating/updating the user's record to set their expiration date you could use something like the following UPDATE users SET expiration = DATE_ADD(NOW(), INTERVAL 30 DAY) WHERE user_id = $user_id Now there is no need to update the expiration value each day for all users. When the user accesses the site, determine if the expiration date is after the current date. If so, the user is a premium member. If not, they are a standard member. Quote Link to comment Share on other sites More sharing options...
brucegre94 Posted March 28, 2011 Author Share Posted March 28, 2011 If you're doing what I think you're doing, you should set the expiry date to be today's date + 30 days. Then the account is expired when the current date is after the expiry date. So date("m/d/y") + 30 ? There is an easier way. When creating/updating the user's record to set their expiration date you could use something like the following UPDATE users SET expiration = DATE_ADD(NOW(), INTERVAL 30 DAY) WHERE user_id = $user_id Now there is no need to update the expiration value each day for all users. When the user accesses the site, determine if the expiration date is after the current date. If so, the user is a premium member. If not, they are a standard member. so <? $con = mysql_connect("$host","$username","$password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("$db_name", $con); $result = mysql_query("SELECT * FROM $tbl_name WHERE myusername='$myusername'"); while($row = mysql_fetch_array($result)) { $premium = $row['premium']; echo ""; } if ($premium < date(m/d/y){ echo 'Standard <a href="upgrade.php">'; echo 'Upgrade'; echo '</a>'; echo '</td>'; } elseif ($premium > date(m/d/y) { echo 'Premium'; echo '</td>'; } else { } mysql_close($con); ?> I have been teaching myself php and this is fustrating me. Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 28, 2011 Share Posted March 28, 2011 More like this $query = "SELECT IF(`premium`>=NOW(), 1, 0) as premium FROM $tbl_name WHERE myusername='$myusername'"; $result = mysql_query($query); $row = mysql_fetch_array($result); if (!$row['premium']) { echo 'Standard <a href="upgrade.php">'; echo 'Upgrade'; echo '</a>'; echo '</td>'; } else ($premium > date(m/d/y) { echo 'Premium'; echo '</td>'; } Quote Link to comment Share on other sites More sharing options...
brucegre94 Posted March 28, 2011 Author Share Posted March 28, 2011 More like this $query = "SELECT IF(`premium`>=NOW(), 1, 0) as premium FROM $tbl_name WHERE myusername='$myusername'"; $result = mysql_query($query); $row = mysql_fetch_array($result); if (!$row['premium']) { echo 'Standard <a href="upgrade.php">'; echo 'Upgrade'; echo '</a>'; echo '</td>'; } else ($premium > date(m/d/y) { echo 'Premium'; echo '</td>'; } Thank you so much. Could you tell me how I would update my database. After they pay me I check the IPN via paypal and send them to a page that changes the value of the experiation date, but I cannot make it add 30 days to the date. Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 28, 2011 Share Posted March 28, 2011 Could you tell me how I would update my database. After they pay me I check the IPN via paypal and send them to a page that changes the value of the experiation date, but I cannot make it add 30 days to the date. I already gave you an example of the UPDATE query in my first response. Quote Link to comment Share on other sites More sharing options...
brucegre94 Posted March 28, 2011 Author Share Posted March 28, 2011 Could you tell me how I would update my database. After they pay me I check the IPN via paypal and send them to a page that changes the value of the experiation date, but I cannot make it add 30 days to the date. I already gave you an example of the UPDATE query in my first response. It doesn't add a date. It adds DATE_ADD(NOW(), INTERVAL 30 DAY) to the database. Quote Link to comment Share on other sites More sharing options...
trq Posted March 28, 2011 Share Posted March 28, 2011 Post your code. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted April 20, 2011 Share Posted April 20, 2011 select datediff(now(), purchase_date) as days from my_table; Returns the number of days between the two dates 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.