To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > Misc Help > ClientSide Technologies

ClientSide Technologies Discuss HTML/CSS/Javascript, and any other client-side technologies, here.

Reply
 
Thread Tools Rate Thread Display Modes
Old 06-29-2006, 10:08 PM   #1
seanko
Junior Member
 
Join Date: May 2006
Posts: 3
Birthday Script - Javascript/PHP

Hi, i recently found a script which contains an array of peoples birthdays and displays them when their birthdays are. I have a slight problem... My website is in php and i have a mysql database. I need the script to be in php and the array to be taken from a mysql database or from a flat file (preferably the database ).
Also, if its not too much trouble, can someone please make it display the persons age?
Well here is the script anyway, i'll include another one with the age variable if it is any help.
HTML Code:
<html>
<head>
<title>Birthday List</title>
<script type="text/javascript">
//the bday array data can be generated from server-side
var arrBday = [
  ['John Doe', '5/6'],
  ['John Doe1', '5/31'],
  ['John Doe2', '5/30'],
  ['John Doe3', '5/28'],
  ['John Doe4', '5/27'],
  ['John Doe5', '5/18'],
  ['John Doe6', '5/20'], 
  ['John Doe7', '5/19']
  //...and so on (last entry must not have a trailing comma)
];

function getBdaysThisWeek(){
  var arrMonth = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
  var bday, idx;
  var bdayList = new Array();
  var today = new Date();

  for (var i=0;i<arrBday.length;i++){
    var bday = new Date(arrBday[i][1] + '/' + today.getFullYear());
    if (isNaN(bday)) continue;

    if ( isBdayInRange(bday, 7) ){
       idx = bdayList.length;
       bdayList[idx] = new Object();
       bdayList[idx].name = arrBday[i][0];
       bdayList[idx].bday = bday;
       bdayList[idx].month = arrMonth[bday.getMonth()];      
    }
  }
  if (bdayList.length > 0){ //sort asc by birthdate
     bdayList.sort(
       function(a, b){
         if (a.bday < b.bday) return -1
         if (a.bday > b.bday) return 1;
         return 0;
       }
     );
  }
  return bdayList;
}

function isBdayInRange(bday, interval){
//credit for this function goes to:
//-Rob (@slingfive) Eberhardt, Slingshot Solutions
//http://slingfive.com/pages/code/jsDate/jsDate.html

  var today = new Date(); 
  //have to override time so entire day will be valid
  today.setHours(0,0,0,0);
  //if the birthday has already occurred in the year, increment to the next year
  if (bday < today)
    bday.setFullYear(bday.getFullYear() + 1);
  
  // get ms between dates (UTC) and make into "difference" date
  var iDiffMS = bday.valueOf() - today.valueOf();
  //divide iDiffMS by 1000, Seconds, Minutes, Hours
  nDays = parseInt(iDiffMS / 1000 / 60 / 60 / 24);
  
  if(parseInt(nDays) <= parseInt(interval))
    return true;
  else
    return false;
}

function displayBdayList(){
  var date = new Date().getDate();	
  var bdayList = getBdaysThisWeek();
  var len = bdayList.length;
  var s = "<h1>Birthday Celebrants for this week:</h1>";
  if (len>0){
    s += '<ul>';
    for (var i=0; i<len; i++){
       //be mindful of the string-line continuation character (\) at the end of the first line
		s += '<li' + ((date == bdayList[i].bday.getDate())?' class="bdayToday"':'')+ '>\
					<strong>' + bdayList[i].name + '</strong> - ' 
					+ bdayList[i].month + ' ' + bdayList[i].bday.getDate() + '</li>';       
    }
    s += '</ul>';
  }
  else{
    s += "No birthday celebrant for this week.";
  }
  document.write(s);
}
</script>
<style type="text/css">
body {
  font:14px Verdana;
}
/*display style when bday is today*/
.bdayToday {
  color: red;
}
</style>
</head>
<body>
<script type="text/javascript">
displayBdayList();
</script>
</body>
</html>
Here's the one with the age but only displays on day not in week.

HTML Code:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Birthday List</title>
</head>

<body>
<script language="JavaScript">

var arrBday = [
['Bob','11/23/1973'],
['Peter','5/20/1977'],
['John','9/22/1999']
];

function displayBdayList(today){
  var bday,strList='';
  for (var i=0;i<arrBday.length;i++){
    bday = new Date(arrBday[i][1]);
    if (!isNaN(bday) && bday.getMonth()==today.getMonth() && bday.getDate()==today.getDate()) 
	strList+='- '+arrBday[i][0]+" ("+(today.getFullYear()-bday.getFullYear())+")<br>";
  }
  if (strList=='') strList='- NONE'
  document.write("<h4>Today's Birtdays:</h4>"+strList)
}

displayBdayList(new Date());
</script>
</body>

</html>


Thanx, Seanko
seanko is offline   Reply With Quote
Old 07-02-2006, 02:43 PM   #2
bradgrafelman
Pna lbh ernq guvf?
 
Join Date: Jul 2004
Location: 40.566N -89.731W, ~469ft above sea level
Posts: 11,488
Here is a birthday script I found on HotScripts.
__________________
***If your problem has been solved, PLEASE click the RESOLVED LINK under "Thread Tools"***

"Well Bones, do the new medical facilities meet with your approval?" -- Kirk
"They do not. It's like working in a damn computer center" -- McCoy (Star Trek: TMP)

Useful links: Debugging 101 || NJOE || (Sig image) || Rolla Engineered Solutions, LLC
bradgrafelman is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 06:19 AM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.