Jump to content

Todays Birthdays


napsburypark

Recommended Posts

Hi Everyone.

 

I work at a UK Secondary School who want displayed on screens around the school students whos birthdays are today.

 

From our school database its exports the students First Name, Last Name, Class Year, DOB (Format example 01 February 2010)

 

What i would really like is for somebody to help me display this information if i were to put it in to a MYSQL Database.

 

I need a code to display the students name First & Last and their Class Year on the correct date.

 

If anybody could help I would be most grateful.

 

Thank you.

Link to comment
Share on other sites

I am not going to write the code for you, but I'm happy to help get you started,

 

First of all you need to create the database and table,

Lets say you have a table called birthdays with 56 fields

ID, FirstName, LastName, ClassYear, DOB, tempDOB

ID = medium INT

FirstName, LastName, ClassYear & tempDOB= VarChar(50)

DOB = DATE

 

First we need to import your data into the table, this depends on the format you have so i suggest getting it into excel (or something) and saving as a CSV file, frmo that you can create an importer or find one (theirs tons) you could use phpmyadmin, if you wish to list the data and edit the data online then we can work on that later..

 

okay now import the date of birth into `tempDOB` and NOT `DOB`, the reason for this is, because while "01 February 2010" looks nice its not so nice when coding with, so we need to convert the pretty text into some useful data, to show an example try this

date_default_timezone_set('Europe/London');
$date = "01 February 2010";
$phptime = strtotime($date);
echo "$phptime = ".date("d F Y",$phptime);

result (something like)

12345678 = 01 February 2010

 

alot of work for no real gain you maybe thinking.. well when searching for a date or sorting by date it proves very useful..

So a quick little script to update the DOB field

//Update DOB
date_default_timezone_set('Europe/London');
$SQLSelect = "SELECT ID, DOBTemp from birthdays";
$result = mysql_query($SQLSelect) or die($SQLSelect."\n".mysql_error());
while($row = mysql_fetch_assoc($result)){
$SQLUpdate = sprintf("UPDATE birthdays SET DOB = %d WHERE ID = %d",strtotime($row['DOBTemp']),$row['ID']);
mysql_query($SQLUpdate) or die($SQLUpdate."\n".mysql_error());
}

You could probably do this directly from MySQL like this,

UPDATE birthdays SET DOB = STR_TO_DATE(`DOBTemp`,"%d %M %Y");

 

Now view the data in PHPMyAdmin to check its all fine :)

when you sure you could drop the DOBTemp field (if you want to save space, but keep it until your sure)

Now to show thw birthdays a simple script should do it

//Show Birthday
date_default_timezone_set('Europe/London');
$SQLSelect = "SELECT *, YEAR(NOW())-YEAR(DOB) as Age from birthdays WHERE DAYOFYEAR(DOB) = DAYOFYEAR(NOW())";
$result = mysql_query($SQLSelect) or die($SQLSelect."\n".mysql_error());
echo "Happy Birthday (plz beat the hell out of)<BR />\n";
while($row = mysql_fetch_assoc($result)){
echo $row['FirstName']." ".$row['LastName']." - ".$row['ClassYear']." is ".$row['Age']." today<BR />\n";
}

 

Note that , YEAR(NOW())-YEAR(DOB) as Age works out the persons age.

 

Okay, i haven't proof read or tested the above, but should get you started

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.