Furry stuff, oekaki stuff, and other stuff.
You are not logged in.
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 . " ";
}
} while ($my_row = mysql_fetch_array($my_result));
}
if ($message <> "") {
$finalmessage = "<span style=\"color:red;\">Birthday greets to: " . $message . "</span><br /> <br />";
echo $finalmessage;
}
?>
Offline
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.
<?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
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
Is there some code I could add in this to make it play a midi file once through?
Offline
Trunksi wrote:
is this code still working?
No, the database code has changed. Here's an updated version (with a few fixes):
<?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