Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 4 FirstFirst 1234 LastLast
Results 16 to 30 of 48

Thread: Birthday Script

  1. #16
    New to the CF scene
    Join Date
    Nov 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yep. Had a comma missing.
    That fixed it.

  2. #17
    New to the CF scene
    Join Date
    Nov 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh, and how do I make it so that it doesn't show the actual birthday or just shows the month and day, but not the year?
    Last edited by notcalvin; 11-18-2005 at 09:12 PM.

  3. #18
    Regular Coder Nischumacher's Avatar
    Join Date
    Oct 2005
    Location
    Bombay, India
    Posts
    196
    Thanks
    0
    Thanked 2 Times in 2 Posts
    i think at the moment it is displaying the name along with the age... which is linked to respective individuals page...

    it is not displaying there actual birthday...

    if you don't want to display the age... then just remove bdayList[i].age from displayBdayList function.
    - NS 666
    .net DEVILoper

  4. #19
    New to the CF scene
    Join Date
    Nov 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yeah, I did that.
    What I'd really like it to do is display the name and the month/day of the birthday, but not the year.

    I edited it enough to work for my needs currently - just displays the name of the person with a birthday today and within the next 14 days without showing any actual dates (or links for that matter).

  5. #20
    Regular Coder
    Join Date
    Aug 2005
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Happy Birthday to abc.

    Post moved by Swatisonee to Php- sorry about that..
    Last edited by swatisonee; 12-15-2005 at 04:24 AM.

  6. #21
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi
    Is it possible to create the array of birthdays trough a subsciber box.
    So you would have a field with
    Name
    Url
    Birthday: DD/MM/YYYY
    and upon submit it automaticly added to the array.

  7. #22
    New to the CF scene
    Join Date
    Jan 2006
    Location
    Cagayan de Oro City, Ph
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi glenn i'm new here, anyway i used these codes and it's pretty much working but can ask you how to edit this so that it will display all birthday celebrants per month not per day?

    Quote Originally Posted by glenngv
    Well, how about this:

    Code:
    <script language="JavaScript">
    
    var arrBday = [
    ['Bob','11/23/1973'],
    ['Peter','9/22/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>

  8. #23
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,047
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Code:
    <html>
    <head>
    <title>Birthday List</title>
    <script type="text/javascript">
    //the bday array data can be generated from server-side
    var arrBday = [
      ['Bob', '1/1/1973'],
      ['Glenn', '2/4/1989'],
      ['Nathan', '1/26/1999'],
      ['Peter', '1/27/1977'],
      ['John', '1/26/1999'] 
      //...and so on (last entry must not have a trailing comma)
    ];
    
    function getBdayList(month){
      var bday, idx;
      var today = new Date();
      var bdayList = new Array();  
      for (var i=0;i<arrBday.length;i++){
        bday = new Date(arrBday[i][1]);
        if (isNaN(bday)) continue;
        if (month == bday.getMonth()){
           idx = bdayList.length;
           bdayList[idx] = new Object();
           bdayList[idx].name = arrBday[i][0];
           bdayList[idx].bday = bday;
           bdayList[idx].age = today.getFullYear() - bday.getFullYear();       
        }
      }
      if (bdayList.length > 0){ //sort asc by birthdate
         bdayList.sort(
           function(a, b){
             if (a.bday.getDate() < b.bday.getDate()) return -1;
             if (a.bday.getDate() > b.bday.getDate()) return 1;
             return 0;
           }
         );
      }
      return bdayList;  
    }
    
    function displayBdayList(){
      var arrMonth = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "August", "October", "November", "December");
      var month = new Date().getMonth();
      var date = new Date().getDate();
      var monthName = arrMonth[month];
      var bdayList = getBdayList(month);
      var len = bdayList.length;
      var s = "<h1>Birthday Celebrants for the Month of " + monthName + "</h1>";
      if (len>0){
        s += '<ul>';
        for (var i=0; i<len; i++){
           //no age
           s += '<li' + ((date == bdayList[i].bday.getDate())?' class="bdayToday"':'') + '><strong>' + bdayList[i].name + "</strong> - " + monthName + " " + bdayList[i].bday.getDate() + "</li>";
    
           //with age
           //s += '<li' + ((date == bdayList[i].bday.getDate())?' class="bdayToday"':'') + '><strong>' + bdayList[i].name + "</strong> - " + monthName + " " + bdayList[i].bday.getDate() + " (" + bdayList[i].age + ")</li>";
        }
        s += '</ul>';
      }
      else{
        s += "No birthday celebrant for this month.";
      }
      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>

  9. #24
    New to the CF scene
    Join Date
    Jan 2006
    Location
    Cagayan de Oro City, Ph
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks very much glenn, it took me a hard a time to find this script not knowing that I can only find it here with your help.

  10. #25
    New to the CF scene
    Join Date
    Mar 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question is there anyway you can edit this code...

    To use with a database?

    I have a database with over 1500 birthday's...
    [firstname] [lastname] [birthday]

    Is there any way to edit this script to work with a mysql database?

    would rather use php with it, I realize this thread is in the javascript section, but please let me know.
    Thanks!

  11. #26
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,047
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Quote Originally Posted by CubsHub
    To use with a database?

    I have a database with over 1500 birthday's...
    [firstname] [lastname] [birthday]

    Is there any way to edit this script to work with a mysql database?

    would rather use php with it, I realize this thread is in the javascript section, but please let me know.
    Thanks!
    Just generate this javascript array from php:
    Code:
    //the bday array data can be generated from server-side
    var arrBday = [
      ['Bob', '1/1/1973'],
      ['Glenn', '2/4/1989'],
      ['Nathan', '1/26/1999'],
      ['Peter', '1/27/1977'],
      ['John', '1/26/1999'] 
      //...and so on (last entry must not have a trailing comma)
    ];

  12. #27
    New to the CF scene
    Join Date
    Mar 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm gonna try to make a fetch from a mysql database when i get home. I can use <?php tags inside the birthdaylist array, right?

  13. #28
    New to the CF scene
    Join Date
    Mar 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hm... this isnt working to me...
    I tried to use this code:

    PHP Code:


    <script type="text/javascript">
    //the bday array data can be generated from server-side
    var arrBday = [
      ['Emelie', '8/26/1990'],
      ['Truls', '9/4/1989'],
      ['Tobias', '5/26/1989'],
      ['Andrea', '4/20/1990'],
      ['Truls', '9/4/1989'],
      ['Magnus', '3/7/1990'],
      ['Kristine', '5/12/1990'],
      ['Rebecca', '3/24/1990'],
      ['Hedda', '1/15/1987'],
      ['Petter', '5/25/1989'],
      ['Erlend', '10/24/1989'],
      ['Beate', '8/27/1990'],
      ['Karianne', '11/30/1990'],
      ['Karianne', '12/15/1990'],
      ['Kristina', '2/20/1990'],
      ['Cathrine', '11/2/1987'],
      ['Magnus', '4/23/1978'],
      ['Daniel', '7/12/1989'],
      ['KES', '2/13/1970'],
      ['Kjetil', '7/12/1989'],
      ['Tessa', '7/27/1990'],
      ['Aurora', '6/8/1990'],
      ['Andreas', '8/14/1986'],
      ['Camilla', '11/17/1989'],
      ['Julia', '4/21/1987'],
      
      <?php
      
         $conn 
    mysql_connect("localhost","username","password");
       
    mysql_select_db(username) or die(mysql_error());
      
    $getposts mysql_query("SELECT * FROM birthdays");
    while(
    $r=mysql_fetch_array($getposts)){
        
        
    $name$r["name"];
        
    $date$r["date"];

    echo 
    "['$name', '$date'],";
    }
    ?>

      ['Busk', '5/12/1990']
      //...and so on (last entry must not have a trailing comma)
    ];

    function getBdayList(month){
      var bday, idx;
      var today = new Date();
      var bdayList = new Array();  
      for (var i=0;i<arrBday.length;i++){
        bday = new Date(arrBday[i][1]);
        if (isNaN(bday)) continue;
        if (month == bday.getMonth()){
           idx = bdayList.length;
           bdayList[idx] = new Object();
           bdayList[idx].name = arrBday[i][0];
           bdayList[idx].bday = bday;
           bdayList[idx].age = today.getFullYear() - bday.getFullYear();       
        }
      }
      if (bdayList.length > 0){ //sort asc by birthdate
         bdayList.sort(
           function(a, b){
             if (a.bday.getDate() < b.bday.getDate()) return -1;
             if (a.bday.getDate() > b.bday.getDate()) return 1;
             return 0;
           }
         );
      }
      return bdayList;  
    }

    function displayBdayList(){
      var arrMonth = new Array("Januar", "Februar", "Mars", "April", "Mai", "Juni", "Juli", "August", "September", "August", "Oktober", "November", "Desember");
      var month = new Date().getMonth();
      var date = new Date().getDate();
      var monthName = arrMonth[month];
      var bdayList = getBdayList(month);
      var len = bdayList.length;
      var s = "<h3>Bursdager i " + monthName + "</h3>";
      if (len>0){
        for (var i=0; i<len; i++){
           //no age
          // s += '<li' + ((date == bdayList[i].bday.getDate())?' class="bdayToday"':'') + '><strong>' + bdayList[i].name + "</strong> - " + monthName + " " + bdayList[i].bday.getDate() + "</li>";

           //with age
           s += '&middot;&nbsp;' + ((date == bdayList[i].bday.getDate())?' ':'') + '<strong>' + bdayList[i].name + "</strong> - " + monthName + " " + bdayList[i].bday.getDate() + " (" + bdayList[i].age + ")<br>";
        }
      }
      else{
        s += "Ingen bursdager denne måneden.";
      }
      document.write(s);
    }
    </script>
    But it doesnt work...
    I have a databasetable called "birthdays" and with 3 rows: id, name and date.

    Can anyone see whats wrong? I don't get any errormessages, it just don't display anything

  14. #29
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb

    hi glenn. i really admire your script! it is awesome. Just one thing happened to come accross my mind.. Can you please make me a script like you made for nathan, but just change it a bit and if possible, make the array in a seperate file:
    • can you change it so that it displays the birthdays in the next 7 days.
    • when it displays somebody's birthday, can you change the format to:
    [name] turns [age] today
    [name] turns [age] in 4 days
    • also as i mentioned above, can make the script read another file with this array?
    • Finally, if possible, can you write it in php

  15. #30
    New to the CF scene
    Join Date
    May 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Glenn, i'd like to use the code you mentioned wrote in your second post, but using the DD/MM configuration and without displaying the year of birth, just day and month. Last thing, i'd like it to display the birthdays in the next 7 days.

    thanks, congrats


 
Page 2 of 4 FirstFirst 1234 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •