jeremaitland Posted September 1, 2009 Share Posted September 1, 2009 I need help with a code. Im looking to create a link when a users birthday is reached. I want a link to show up on thier login page when their birthday is up to 7 days away. I have got several scripts and cant get any to work. The birthday of a user is saved in a date feild in mysql (format 0000-00-00). the page already brings up just their information so i dont understand what is wrong. Here is the script i cant get to work. <?php $birthday2 = $row_settings['birthday2']; $thisday = date("j")+1-1; //get today's date as 1-31 $thismonth = date("n")+1-1; //get month as 1-12 $pieces = explode("-",$birthday2); $bday = $pieces[2]+1-1; //Addition makes it an integer $bmonth = $pieces[1]+1-1; //if you want the year, it's in $pieces[0] if ($bday < 7) { //birthday is too close to beginning of month, move it to previous month, add days //eg. 2nd December becomes 32nd November $bmonth -= 1; if ($bmonth == 0) { $bmonth = 12; } switch ($bmonth) { case 4: case 6: case 9: case 11: $bday += 30; break; case 2: if (date("L") == 1) { $bday += 29; } else { $bday += 28; } break; default: $bday += 31; } } //check if months match if ($thismonth == $bmonth) { //they match, so now compare days if ($thisday<$bday && ($bday-$thisday) <= 7 ) { echo ("birthday is with in 7 days <a href=coupons.php>Click Here</a>"); } } ?> I have header scripts that gets the information from just that user and they are: <? while ($row_settings = mysql_fetch_array($rs_settings)) {?> //This script ends after the birthday script. <?$rs_settings = mysql_query("select * from users where id='$_SESSION[user_id]'");?> Link to comment https://forums.phpfreaks.com/topic/172739-need-help-with-mysql-and-php-script/ Share on other sites More sharing options...
waynew Posted September 1, 2009 Share Posted September 1, 2009 You do know that you can do things like this, don't you? $seven_days_before = date('Y-m-d H:i:s', mktime(date('H'),date('i'),date('s'), date('m'),date('d')-7,date('Y'))); $now = date('Y-m-d H:i:s', mktime(date('H'),date('i'),date('s'), date('m'),date('d'),date('Y'))); Link to comment https://forums.phpfreaks.com/topic/172739-need-help-with-mysql-and-php-script/#findComment-910517 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.