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 Link to comment https://forums.phpfreaks.com/topic/231908-trying-to-minus-all-rows-in-1-colum/ 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? Link to comment https://forums.phpfreaks.com/topic/231908-trying-to-minus-all-rows-in-1-colum/#findComment-1193080 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. Link to comment https://forums.phpfreaks.com/topic/231908-trying-to-minus-all-rows-in-1-colum/#findComment-1193081 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. Link to comment https://forums.phpfreaks.com/topic/231908-trying-to-minus-all-rows-in-1-colum/#findComment-1193083 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 ? Link to comment https://forums.phpfreaks.com/topic/231908-trying-to-minus-all-rows-in-1-colum/#findComment-1193085 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. Link to comment https://forums.phpfreaks.com/topic/231908-trying-to-minus-all-rows-in-1-colum/#findComment-1193386 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. Link to comment https://forums.phpfreaks.com/topic/231908-trying-to-minus-all-rows-in-1-colum/#findComment-1193413 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>'; } Link to comment https://forums.phpfreaks.com/topic/231908-trying-to-minus-all-rows-in-1-colum/#findComment-1193424 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. Link to comment https://forums.phpfreaks.com/topic/231908-trying-to-minus-all-rows-in-1-colum/#findComment-1193425 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. Link to comment https://forums.phpfreaks.com/topic/231908-trying-to-minus-all-rows-in-1-colum/#findComment-1193432 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. Link to comment https://forums.phpfreaks.com/topic/231908-trying-to-minus-all-rows-in-1-colum/#findComment-1193443 Share on other sites More sharing options...
trq Posted March 28, 2011 Share Posted March 28, 2011 Post your code. Link to comment https://forums.phpfreaks.com/topic/231908-trying-to-minus-all-rows-in-1-colum/#findComment-1193452 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 Link to comment https://forums.phpfreaks.com/topic/231908-trying-to-minus-all-rows-in-1-colum/#findComment-1203815 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.