busnut Posted January 22, 2009 Share Posted January 22, 2009 G'day guys I've got a membership database running on my site, and I need a script that once the user's logged in, I want it to perform a check against their membership to see if their renewal is coming up or past its expirey date. This is what i'm looking for: if renewal date expires within the next 30 days, then display 'Your membership renewal is due in X days' if renewal date is todays date, then display 'Your membership renewal is due TODAY' if renewal date has passed and no more than 30 days, 'Your Membership renewal has now passed, please renew your membership NOW' if renewal date is more than 30 days, then popup 'Your membership has now lapsed' and then once ok is pressed, will log user off. the renewal field in the mysql database/table is 'renewal', and the format is yyyy-mm-dd. I have tried at least get if renewal = todays date then display 'Your membership renewal is due TODAY', but the 2 ways i've tried it, will either show when it shouldn't, doesn't show when it should Any help greatly appreciated. But somehow i'm sure you may need some of my coding, but not sure which part from which script you may need! Link to comment https://forums.phpfreaks.com/topic/141923-if-date-scenareo/ Share on other sites More sharing options...
Mchl Posted January 22, 2009 Share Posted January 22, 2009 Show us what you tried, and we'll start from there Link to comment https://forums.phpfreaks.com/topic/141923-if-date-scenareo/#findComment-743115 Share on other sites More sharing options...
busnut Posted January 22, 2009 Author Share Posted January 22, 2009 i've tried $todaysdate = $date; if($euRenewal==$todaysdate) echo "Your membership renewal is due TODAY!"; else echo ""; and $todaysdate = $date; if($renewal==$todaysdate) echo "Your membership renewal is due TODAY!"; else echo ""; see in the table, the field name is renewal, but once the user logs in, because the system checks against the users permission status (ie, whether they are admin, member or committee member, depends on what they can do), so therefor all fields have 'eu' in front of them. See most users have same common renewal date (yyyy-06-30), although we may soon remove the common renewal date and replace it with a year from the day they pay their membership rather than have an decremental membership fees, but the admin account, I changed from 0000-00-00 to todays date and even another date in advance to check to see if the message displays, and it displays the message regardless So, firstly what I have above, would that work or am I missing code? and secondly, do I have to have a query above the code, although every page has an include to check the userauth page? Link to comment https://forums.phpfreaks.com/topic/141923-if-date-scenareo/#findComment-743122 Share on other sites More sharing options...
landavia Posted January 22, 2009 Share Posted January 22, 2009 this like Cellphone provider in my country i assume there DB and table *username *renewal let asume we have $ren => renewal <?php $ren="2009-10-10"; $ren2=strtotime($ren); //return int $now2=strtotime("now"); $exp=30*24*60*60; //if renewal date expires within the next 30 days, then display 'Your membership renewal is due in X days' $div=$ren2-$now2; if($div<=$exp&&$div>3600) { $tm=ceil($div/3600); echo 'Your membership renewal is due in '.$tm.' days'; } //if renewal date is todays date, then display 'Your membership renewal is due TODAY' if($div<3600) { echo 'Your membership renewal is due TODAY'; } //if renewal date has passed and no more than 30 days, 'Your Membership renewal has now passed, please renew your membership NOW' $div=$now2-$ren2; if($div<$exp) { echo 'Your Membership renewal has now passed, please renew your membership NOW'; }else{ //if renewal date is more than 30 days, then popup 'Your membership has now lapsed' and then once ok is pressed, will log user off. header("location:kick.php"); } ?> Link to comment https://forums.phpfreaks.com/topic/141923-if-date-scenareo/#findComment-743127 Share on other sites More sharing options...
printf Posted January 22, 2009 Share Posted January 22, 2009 Do a join on the renewal table when they login. You can also have another table that you can join that contains the message related to the value returned in renewal column, this way you don't have to do any PHP scripting, meaning the database returns everything for you. Link to comment https://forums.phpfreaks.com/topic/141923-if-date-scenareo/#findComment-743141 Share on other sites More sharing options...
busnut Posted January 22, 2009 Author Share Posted January 22, 2009 the above script supplied sorta worked in a way that it would display the messages, but not when they should've. Also if the users renewal date wasn't within the time period, it also displayed a message that couldn't redo headers Just prior to getting a notification of the script you had provided, I got this to work, and it works EXCEPT that on first login, doesn't display the message until the user clicks another link <? $todays_date = date("Y-m-d"); if ($todays_date == $euRenewal) { echo "Your membership renewal is due TODAY!"; } ?> So that seems relatively basic, just need the 30 days before and after and then 31 days after expired, so where can the snippet above go to help? Link to comment https://forums.phpfreaks.com/topic/141923-if-date-scenareo/#findComment-743147 Share on other sites More sharing options...
landavia Posted January 22, 2009 Share Posted January 22, 2009 the above script supplied sorta worked in a way that it would display the messages, but not when they should've. Also if the users renewal date wasn't within the time period, it also displayed a message that couldn't redo headers Just prior to getting a notification of the script you had provided, I got this to work, and it works EXCEPT that on first login, doesn't display the message until the user clicks another link <? $todays_date = date("Y-m-d"); if ($todays_date == $euRenewal) { echo "Your membership renewal is due TODAY!"; } ?> So that seems relatively basic, just need the 30 days before and after and then 31 days after expired, so where can the snippet above go to help? wait a moment.. i convert the date into integer.. and that's make everything easy i think what the next problem? Link to comment https://forums.phpfreaks.com/topic/141923-if-date-scenareo/#findComment-743150 Share on other sites More sharing options...
busnut Posted January 22, 2009 Author Share Posted January 22, 2009 Ok, this is where my knowledge or lack thereoff starts to fail, i'm lost as to what you meant by integer? Is that where the real date is converted to a digit computer format? But as for the next problem, well really if this works (well once the page has been refreshed), using the code that I supplied if possible, can i then go if $todays_date is between 1 to 30 days prior to $euRenewal date then display this msg if $todays_date is between than 1 to 30 days after $euRenewal date then display this msg if $todays_date is 31 days or more than $euRenewal date then display this msg and return to logout as this section certainly is beyond my knowledge, this is where and why I need the help... Link to comment https://forums.phpfreaks.com/topic/141923-if-date-scenareo/#findComment-743157 Share on other sites More sharing options...
landavia Posted January 22, 2009 Share Posted January 22, 2009 >>well really if this works well.. if you ask if this work.. i'm not try it but i positif what i type worked.. perhaps there another way to solve it? Link to comment https://forums.phpfreaks.com/topic/141923-if-date-scenareo/#findComment-743165 Share on other sites More sharing options...
busnut Posted January 23, 2009 Author Share Posted January 23, 2009 Ok, i've had somewhat success in what i'm achieving, although after several hours of trying to do one other bit, still having no luck (so any help greatly apprecated, as they say programming involves maths, well I failed maths in high school). this is what works // displays message if within a month after the rewewal date else if ($todays_date > $euRenewal && $todays_date < $euRenewal + date(m,1)) echo " **renewal overdue** "; // displays message if after one month of the renewal date else if ($todays_date > $euRenewal && $euRenewal > date(m,1)) echo " **membership expired** "; ?> what works, but can't get the right equation as it displays all year round up until the renewal date is: if ($todays_date < $euRenewal [need rest of equation in here]) echo " **renewal due** "; Link to comment https://forums.phpfreaks.com/topic/141923-if-date-scenareo/#findComment-744005 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.