napsburypark Posted February 4, 2010 Share Posted February 4, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/190953-todays-birthdays/ Share on other sites More sharing options...
roopurt18 Posted February 4, 2010 Share Posted February 4, 2010 One of my favorite memories from 7th and 8th grade were when groups of ill-tempered students would physically injure the kids whose birthday it was on that given day. Good intentions gone awry by the school's administrators. Quote Link to comment https://forums.phpfreaks.com/topic/190953-todays-birthdays/#findComment-1006969 Share on other sites More sharing options...
MadTechie Posted February 4, 2010 Share Posted February 4, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/190953-todays-birthdays/#findComment-1007018 Share on other sites More sharing options...
napsburypark Posted February 14, 2010 Author Share Posted February 14, 2010 Someones help would really be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/190953-todays-birthdays/#findComment-1012284 Share on other sites More sharing options...
jl5501 Posted February 14, 2010 Share Posted February 14, 2010 You have been given some comprehensive help. If you have specific problems implementing that, then I am sure someone here will help you Quote Link to comment https://forums.phpfreaks.com/topic/190953-todays-birthdays/#findComment-1012290 Share on other sites More sharing options...
MadTechie Posted February 15, 2010 Share Posted February 15, 2010 Someones help would really be appreciated. Erm.. do you have a question ? I am not going to write the code for you, I believe I have helped! in any case your welcome! Quote Link to comment https://forums.phpfreaks.com/topic/190953-todays-birthdays/#findComment-1012500 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.