birthday reminder

Reply

Join Date: Feb 2009
Posts: 11
Reputation: oskido2010 is an unknown quantity at this point 
Solved Threads: 0
oskido2010 oskido2010 is offline Offline
Newbie Poster

birthday reminder

 
0
  #1
Feb 12th, 2009
Hi
I would like to set up a php birthday reminder so that if users bdays are within the 7 days, it should display that the folllowing people celebrate their bday next week so far i have got to this stage, does any one have a better idea?

  1. if(!empty($_POST)){
  2.  
  3. function birthday ($birthday){
  4.  
  5. list($year,$month,$day) = explode("-",$birthday);
  6. $year_diff = date("Y") - $year;
  7. $month_diff = date("m") - $month;
  8. $day_diff = date("d") - $day;
  9.  
  10. if ($day_diff < 0 || $month_diff < 0)
  11. $year_diff--;
  12. return $year_diff;
  13.  
  14. }
Any ideas will be wolcomed on how I can complete the rest of this code! all I would like is to see which friends or users have their bday in the next 7 days and their age if possible!!
Last edited by digital-ether; 20 Days Ago at 10:29 pm. Reason: Please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 353
Reputation: death_oclock will become famous soon enough death_oclock will become famous soon enough 
Solved Threads: 37
death_oclock's Avatar
death_oclock death_oclock is offline Offline
Posting Whiz

Re: birthday reminder

 
0
  #2
Feb 12th, 2009
1. Use code tags.
2. Use time stamps (functions like mktime, date, etc.) this will make comparing dates much easier.
3. Don't declare functions within control structure. Its just a bizarre practice.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 11
Reputation: oskido2010 is an unknown quantity at this point 
Solved Threads: 0
oskido2010 oskido2010 is offline Offline
Newbie Poster

Re: birthday reminder

 
0
  #3
Feb 12th, 2009
Thanx I am not sure if I understand this!!!

If i use the mktime function for example this one!!
  1. <?php
  2. $tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
  3. echo "Tomorrow is ".date("Y/m/d", $tomorrow);
  4. This code will output = Tomorrow is 2009/02/13

So in order to get this dates from my database, and explode then what will i have to do, i know this is asking too much but could you plz demonstrate on a simple php code!!!
Last edited by digital-ether; 20 Days Ago at 10:29 pm. Reason: Please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 353
Reputation: death_oclock will become famous soon enough death_oclock will become famous soon enough 
Solved Threads: 37
death_oclock's Avatar
death_oclock death_oclock is offline Offline
Posting Whiz

Re: birthday reminder

 
0
  #4
Feb 12th, 2009
If you store the birthdays as timestamps rather than strings it is very easy. Something like this would do:
  1. // $birthday has been selected from the database
  2. if($birthday > time() && $birthday - time() <= (7 * 24 * 60 * 60))
  3. {
  4. //birthday is within seven days
  5. }
Last edited by death_oclock; Feb 12th, 2009 at 4:45 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 11
Reputation: oskido2010 is an unknown quantity at this point 
Solved Threads: 0
oskido2010 oskido2010 is offline Offline
Newbie Poster

Re: birthday reminder

 
0
  #5
Feb 12th, 2009
I have stored my birthdays as DATE type data 1985-02-14, I have got friends table, so how will my query be like in order to get those people in my database who's bdays are within a week? will this still work?
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,312
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 161
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: birthday reminder

 
0
  #6
Feb 12th, 2009
The database is not meant to be human readable, it is machine readable and efficient (we hope),
correct your database design to store dates as a timestamp, it is less overhead to rewrite the adduser script and do a tablewide update of existing records once than it is to constantly
read a record
explode it at '-'
convert it to a timestamp with mktime or strtotoime
compare the timestamp to the current timestamp
store the nickname
read the next record
print the stored names
for a text stored date,
every record must be read and manipulated to collect a date range
TIMESTAMP is hugely faster, (uses less storage space smallint will hold it)
is easier to compare dates, extract a date range
its easier sql to select from tha database
set up the query

  1. SELECT nickname FROM table WHERE birthday BETWEEN CURDATE( ) AND DATE_ADD(CURDATE(), INTERVAL +7 DAY);

to get a list of nicknames/loginnames of users with birthdays in the next seven days
Last edited by almostbob; Feb 12th, 2009 at 5:25 pm. Reason: coz I cant spell
Failure is not an option It's included free
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 11
Reputation: oskido2010 is an unknown quantity at this point 
Solved Threads: 0
oskido2010 oskido2010 is offline Offline
Newbie Poster

Re: birthday reminder

 
0
  #7
Feb 12th, 2009
How will i intergrade the "explode" function within my code, I mean how will i do this same as if i was to consider the 1st posting on the top of this page!
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 353
Reputation: death_oclock will become famous soon enough death_oclock will become famous soon enough 
Solved Threads: 37
death_oclock's Avatar
death_oclock death_oclock is offline Offline
Posting Whiz

Re: birthday reminder

 
0
  #8
Feb 12th, 2009
If you are too stubborn to accept that timestamps are in fact better or are too lazy to make the change, it would look like this:
  1. $parts = explode("-",$birthday);
  2. $yeah = $parts[0];
  3. $month = $parts[1];
  4. $day = $parts[2];
  5. $birthday = mktime(0, 0, 0, $month, $day, $year);
Good thinking on doing it all within MySQL, bob.
Last edited by death_oclock; Feb 12th, 2009 at 5:56 pm.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,312
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 161
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: birthday reminder

 
0
  #9
Feb 12th, 2009
fix the databse
then you dont have to
READ EVERY RECORD IN THE DATABASE
EXPLODE EVERY RECORD
MKTIME
Compare the generated timesatmp and then throw away all records that are not correct

WHAT IF:
you get bigger and there are 2-3 MILLION users at 1/1000 second for each record to make a happy birthday list, plus whatever other user tracking is going on, what are you going to do for the 33minutes - 45minutes your users are waiting for the page to display
  1. $stamp = idate(z,Strtotime($birthday));
  2. if ($stamp >= idate(z) and $stamp < (idate(z)+6)) {echo $nickname;}
for every record in the database

just for the hell of it I put 10000 random records in a database containing nickname and birthday
the sql based query prior took less than 1 second to execute 500 times and extract 500 sets of this weeks birthday

the php query took six seconds to run once and did extract the same three names

on my develpment box which is slower than a server

Fix The Database

in your input processigng you can still input the date as 1985-1-14, but if you explode it above and
or can input birthday as three datebits from drop down selects year month day
  1. $birthday= mktime (0,0,0,$datebits[1],$datebits[2],$datebits[0],0);

and you can fix the table by
  1. UPDATE table SET birthday = %s , strtotime(birthday);

I havent checked what I just typed as the sql, its probably way wrong, using a php function in sql
but its read the birthday value, parse it to a
Last edited by almostbob; Feb 12th, 2009 at 6:24 pm.
Failure is not an option It's included free
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 11
Reputation: oskido2010 is an unknown quantity at this point 
Solved Threads: 0
oskido2010 oskido2010 is offline Offline
Newbie Poster

Re: birthday reminder

 
0
  #10
Feb 12th, 2009
Hope something like this will work perfectly!! any more ideas or suggestions, really appreciate folks:

  1. <?php
  2. option 1
  3. //database connection
  4.  
  5. $parts = explode("-",$birthday);
  6. $year = $parts[0];
  7. $month = $parts[1];
  8. $day = $parts[2];
  9. $birthday = mktime(0, 0, 0, $month, $day, $year);
  10.  
  11. //option 2
  12.  
  13. $datebits = explode('-', $birthday);
  14. $stamp = date(z,mktime (0,0,0,$datebits[1],$datebits[2],$datebits[0],0));
  15.  
  16. if ($stamp >= idate(z) and $stamp < (idate(z)+6)) {echo $nickname;}
  17.  
  18. $birthday=mysql_query("SELECT * FROM users WHERE birthday BETWEEN CURDATE( ) AND DATE_ADD(CURDATE(), INTERVAL +7 DAY);
  19.  
  20. $num_birthday = mysql_num_rows($birthdays);
  21.  
  22. if($birthday > time() && $birthday - time() <= (7 * 24 * 60 * 60))
  23.  
  24. {
  25. while ($row=mysql_fetch_ array($birthdays))
  26. }
  27. elseif ((strtotime($birthbday) - strtotime(now)) <= (7 * 24 * 60 * 60)
  28.  
  29. {echo "this persons birthday is in the next 7 days";}
  30.  
  31. ?>
  32.  
Last edited by digital-ether; 20 Days Ago at 10:32 pm. Reason: Please use [code] tags
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC