NineChime forum

Furry stuff, oekaki stuff, and other stuff.

You are not logged in.

#1 06-23-2006 12:47:09

Nullig
Member

Birthday Greetings

Added birthday greetings to my site. Here's the code if anyone wants it.

In the banners I added this in the notice area: <? include ("birthdays.php"); ?>

Here is the birthdays.php code:

<?php

$my_host = "localhost"; //Hostname
$my_user = "yourusername"; //Database Username
$my_pass = "yourpassword"; //Database password
$my_data =  "yourdatabasename"; //Database name

$my_table = "op_oekaki"; //Table name

$message = "";
$finalmessage = "";

$todaymonth = date("m");
$todayday = date("d");


$my_dbconn = mysql_connect("$my_host", "$my_user", "$my_pass") or die("Could not connect: " . mysql_error());
mysql_select_db("$my_data",$my_dbconn);

$my_result = mysql_query("SELECT * FROM $my_table ORDER BY usrname",$my_dbconn);

if ($my_row = mysql_fetch_array($my_result)) {

  do {

    $username = trim($my_row['usrname']);
    $age = $my_row['age'];
    $birthday = substr($age, -2);
    $birthmonth = substr($age, -5, 2);

    if (($birthday == $todayday) && ($birthmonth == $todaymonth)) {

      $message = $message . $username . "&nbsp;&nbsp;";

    }


  } while ($my_row = mysql_fetch_array($my_result));

}


if ($message <> "") {

  $finalmessage = "<span style=\"color:red;\">Birthday greets to:&nbsp;" . $message . "</span><br />&nbsp;<br />";
  echo $finalmessage;

}

?>

Offline

#2 06-24-2006 16:25:24

Waccoon
Administrator

Re: Birthday Greetings

Hey, cool.

Couple things, though...  you don't need to make a connection to the database if this is included in the notice.  I also have a function called "make_list()" which makes it easier to show lists of names with arrays.  Try out this version.  It can be pasted directly into the notice, or saved as birthday.php and use "<? include ('birthday.php') ?>" in the notice.

Code:

<?php

$birthday_names = array();
$todaymonth = date ("m");
$todayday = date ("d");

$my_result = mysql_query ("SELECT usrname, age FROM {$OekakiPoteto_MemberPrefix}oekaki ORDER BY usrname");

if (mysql_num_rows ($my_result) > 0) {
    while ($my_row = mysql_fetch_array ($my_result)) {
        $age = $my_row['age'];
        $birthday = substr ($age, -2);
        $birthmonth = substr ($age, -5, 2);

        if (($birthday == $todayday) && ($birthmonth == $todaymonth)) {
            $un = trim ($my_row['usrname']);
            $un_url = urlencode ($un);
            $age_years = get_age($age);

            $birthday_names[] = "<a href=\"profile.php?user=\"{$un_url}\">{$un} ({$age_years})</a>";
        }
    }
}

if (count ($birthday_names)) {
    echo ('<span style="color:red;">');
    echo ("Birthday greets to: " . make_list($birthday_names, ', '));
    echo ('</span><br /><br />');
}

?>

Offline

#3 06-24-2006 21:42:27

Nullig
Member

Re: Birthday Greetings

Super. I'll give it a try.

Thanks,

Nullig

Offline

#4 07-16-2006 11:29:33

Nullig
Member

Re: Birthday Greetings

I just noticed in the following line in your script that the \" between user= and {$un_url} was screwing up the link to the user profile. I took it out, and all is well.

$birthday_names[] = "<a href=\"profile.php?user=\"{$un_url}\">{$un} ({$age_years})</a>";

Nullig

Offline

#5 01-17-2008 07:34:04

acwitness
Member

Re: Birthday Greetings

Is there some code I could add in this to make it play a midi file once through?

Offline

#6 03-31-2010 06:12:53

Trunksi
Member

Re: Birthday Greetings

is this code still working?
today it's a members birthday but it doesn't show up
so I thought since the new changes because of some code stuff (PHP6 and such)
it might be not working correctly anymore and that's why it doesn't shows up

Offline

#7 04-01-2010 05:47:16

Waccoon
Administrator

Re: Birthday Greetings

Trunksi wrote:

is this code still working?

No, the database code has changed.  Here's an updated version (with a few fixes):

Code:

<?php
//===========================================================================
// BIRTHDAYS START
//===========================================================================

$birthday_names = array();
$todaymonth = date ("m");
$todayday = date ("d");

$my_result = db_query ("SELECT usrname, age FROM {$OekakiPoteto_MemberPrefix}oekaki ORDER BY usrname");

if ($my_result && db_num_rows($my_result) > 0) {
    while ($my_row = db_fetch_array($my_result)) {
        $my_age = $my_row['age'];
        if (strpos($my_age, '-') !== FALSE && strpos($my_age, '?') === FALSE) {
            list ($byear, $bmonth, $bday) = explode ('-', $my_age);

            $my_bday_pass = FALSE;
            if ($todaymonth == '2' && $todayday == '29') {
                // Leap year birthday?
                if ($bmonth == $todaymonth) {
                    if ($bday == '28' || $bday == '29') {
                        $my_bday_pass = TRUE;
                    }
                }
            } elseif (($bday == $todayday) && ($bmonth == $todaymonth)) {
                $my_bday_pass = TRUE;
            }
            
            if ($my_bday_pass == TRUE) {
                $un = trim($my_row['usrname']);
                $un_url = urlencode($un);
                $un_html = w_html_chars($un);
                $un_years = get_age($my_age);

                $birthday_names[] = "<a href=\"profile.php?user={$un_url}\">{$un_html} ({$un_years})</a>";
            }
        }
    }
}

if (count ($birthday_names) > 0) {
    echo ('<p>');
    echo ("Birthday greetings to: " . make_list($birthday_names, ', '));
    echo ('</p>');
}

//===========================================================================
// BIRTHDAYS END
//===========================================================================
?>

Offline

#8 04-01-2010 08:27:22

Trunksi
Member

Re: Birthday Greetings

it's working again smile
thanks alot for that really fast help big_smile

Offline

Board footer

Yep, still running PunBB
© Copyright 2002–2008 PunBB