| | |
birthday reminder
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Feb 2009
Posts: 11
Reputation:
Solved Threads: 0
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?
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!!
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?
php Syntax (Toggle Plain Text)
if(!empty($_POST)){ function birthday ($birthday){ list($year,$month,$day) = explode("-",$birthday); $year_diff = date("Y") - $year; $month_diff = date("m") - $month; $day_diff = date("d") - $day; if ($day_diff < 0 || $month_diff < 0) $year_diff--; return $year_diff; }
Last edited by digital-ether; 20 Days Ago at 10:29 pm. Reason: Please use [code] tags
•
•
Join Date: Feb 2009
Posts: 11
Reputation:
Solved Threads: 0
Thanx I am not sure if I understand this!!!
If i use the mktime function for example this one!!
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!!!
If i use the mktime function for example this one!!
php Syntax (Toggle Plain Text)
<?php $tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y")); echo "Tomorrow is ".date("Y/m/d", $tomorrow); 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
If you store the birthdays as timestamps rather than strings it is very easy. Something like this would do:
PHP Syntax (Toggle Plain Text)
// $birthday has been selected from the database if($birthday > time() && $birthday - time() <= (7 * 24 * 60 * 60)) { //birthday is within seven days }
Last edited by death_oclock; Feb 12th, 2009 at 4:45 pm.
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
is easier to compare dates, extract a date range
its easier sql to select from tha database
set up the query
to get a list of nicknames/loginnames of users with birthdays in the next seven days
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
TIMESTAMP is hugely faster, (uses less storage space smallint will hold it)read a recordfor a text stored date,
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
every record must be read and manipulated to collect a date range
is easier to compare dates, extract a date range
its easier sql to select from tha database
set up the query
mysql Syntax (Toggle Plain Text)
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
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
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:
Good thinking on doing it all within MySQL, bob.
PHP Syntax (Toggle Plain Text)
$parts = explode("-",$birthday); $yeah = $parts[0]; $month = $parts[1]; $day = $parts[2]; $birthday = mktime(0, 0, 0, $month, $day, $year);
Last edited by death_oclock; Feb 12th, 2009 at 5:56 pm.
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
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
and you can fix the table by
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
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
php Syntax (Toggle Plain Text)
$stamp = idate(z,Strtotime($birthday)); if ($stamp >= idate(z) and $stamp < (idate(z)+6)) {echo $nickname;}
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
php Syntax (Toggle Plain Text)
$birthday= mktime (0,0,0,$datebits[1],$datebits[2],$datebits[0],0);
and you can fix the table by
sql Syntax (Toggle Plain Text)
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
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
•
•
Join Date: Feb 2009
Posts: 11
Reputation:
Solved Threads: 0
Hope something like this will work perfectly!! any more ideas or suggestions, really appreciate folks:
php Syntax (Toggle Plain Text)
<?php option 1 //database connection $parts = explode("-",$birthday); $year = $parts[0]; $month = $parts[1]; $day = $parts[2]; $birthday = mktime(0, 0, 0, $month, $day, $year); //option 2 $datebits = explode('-', $birthday); $stamp = date(z,mktime (0,0,0,$datebits[1],$datebits[2],$datebits[0],0)); if ($stamp >= idate(z) and $stamp < (idate(z)+6)) {echo $nickname;} $birthday=mysql_query("SELECT * FROM users WHERE birthday BETWEEN CURDATE( ) AND DATE_ADD(CURDATE(), INTERVAL +7 DAY); $num_birthday = mysql_num_rows($birthdays); if($birthday > time() && $birthday - time() <= (7 * 24 * 60 * 60)) { while ($row=mysql_fetch_ array($birthdays)) } elseif ((strtotime($birthbday) - strtotime(now)) <= (7 * 24 * 60 * 60) {echo "this persons birthday is in the next 7 days";} ?>
Last edited by digital-ether; 20 Days Ago at 10:32 pm. Reason: Please use [code] tags
![]() |
Similar Threads
- Do I need to use strotime for making a birthday notification. (PHP)
- Help with automatic update problem and more (Viruses, Spyware and other Nasties)
- reminder pop up (Visual Basic 4 / 5 / 6)
- BCC: Multiple Recipient (PHP)
- Saxto.com and saxor.com for sale (Domain Names for Sale)
- Using HTML tags in PHP code (PHP)
- ¶Happy Birthday........ (Geeks' Lounge)
- Various websites for sale (music, investing, online magazines, etc) (Websites for Sale)
Other Threads in the PHP Forum
- Previous Thread: Deleting rows
- Next Thread: Suggestions on X-cart opensource ?
| Thread Tools | Search this Thread |
apache api array auto beginner binary broken cache cakephp checkbox class cms code codingproblem cron curl customizableitems database date display dynamic echo email error errorlog file files filter folder form format forms forum function functions gc_maxlifetime global google headmethod host href htaccess html image include insert ip javascript joomla limit link login mail malfunctioning memmory memory menu mlm multiple mysql nodes oop parameter parsing paypal pdf php phpmysql popup query radio random recursion recursiveloop remote script search select server sessions snippet source space sql static survey syntax system table trouble tutorial up-to-date update upload url validator variable video web youtube






