Birthday hack [message #4352] |
Wed, 24 July 2002 19:09  |
heidiott
 Messages: 34 Registered: May 2002
Karma: 0
|
Member |
|
|
I think it would be fun to have a birthday hack that would pull todays birthdays from the database so that they could be used as an include somewhere on the site... It could say something like...
Todays Birthdays: Username (age), Username (age), etc...
Thank you,
Heidi
|
|
|
|
|
Re: Birthday hack [message #4408 is a reply to message #4352] |
Fri, 26 July 2002 01:01   |
 |
JamesS
 Messages: 275 Registered: July 2002 Location: Atlanta, GA
Karma: 0
|
Senior Member |
|
|
something along these lines would get you going in the right direction:
<?php
$db = mysql_connect(<database server>, <username>, <password>);
mysql_select_db(<forum database>, $db);
$result = mysql_query("SELECT * FROM <formum prefix>_users WHERE bday=" . date("Ymd"), $db);
$row = mysql_fetch_array($result, MYSQL_NUM);
echo $row[3] . " is celebrating his/her birthday today.";
?>
this code will not quite work (only gets one person) but it at least gets you started.
*edit* actually you will have to do a regular expression search for birthdays ending with "md" i believe. so that above code doesnt even return one hit.
[Updated on: Fri, 26 July 2002 02:23] Report message to a moderator
|
|
|
Re: Birthday hack [message #4410 is a reply to message #4408] |
Fri, 26 July 2002 03:11   |
Ilia
 Messages: 13241 Registered: January 2002
Karma: 0
|
Senior Member Administrator Core Developer |
|
|
Except, you'd need to add an INDEX on the bday field, otherwise that query will be VERY slow, especially on forum with many users.
FUDforum Core Developer
|
|
|
|
Re: Birthday hack [message #4688 is a reply to message #4352] |
Fri, 02 August 2002 22:43   |
heidiott
 Messages: 34 Registered: May 2002
Karma: 0
|
Member |
|
|
I did it
Here is the function...
<?php
function bday()
{
include_once "path/to/GLOBALS.php";
$cid = mysql_connect($DBHOST, $DBHOST_USER, $DBHOST_PASSWORD);
mysql_select_db($DBHOST_DBNAME, $cid);
$time = date(m);
$cur_year = date(Y);
$quary ="SELECT id, login, bday FROM fud_users WHERE bday>0";
$result = mysql_query($quary);
//print "This months birthdays...<br>");
while(list($id, $login, $bday) = mysql_fetch_row($result))
{
$month = substr($bday, -4, 2);
$year = substr ($bday, -0, 4);
$age = $cur_year - $year;
if ($month == $time)
{
print ("<a href=\"http://forum_url/index.php?t=usrinfo&id=$id\">$login</a> <span class=\"small\">(<b>$age</b>)</span><br&g t;\n");
}
}
}
?>
Call the function with...
<?php bday(); ?>
I decided to show all birthdays for the current month instead of each day. The code could easily be changed to show birthdays by day.
Have fun!
Heidi
|
|
|
|
|
|
|
Re: Birthday hack [message #13071 is a reply to message #4688] |
Sun, 21 September 2003 12:25  |
 |
aircool5(at)bellsouth(dot)net
 Messages: 132 Registered: March 2003
Karma: 0
|
Senior Member |
|
|
Where I have to paste this code?
heidiott wrote on Fri, 02 August 2002 18:43 | I did it
Here is the function...
<?php
function bday()
{
include_once "path/to/GLOBALS.php";
$cid = mysql_connect($DBHOST, $DBHOST_USER, $DBHOST_PASSWORD);
mysql_select_db($DBHOST_DBNAME, $cid);
$time = date(m);
$cur_year = date(Y);
$quary ="SELECT id, login, bday FROM fud_users WHERE bday>0";
$result = mysql_query($quary);
//print "This months birthdays...<br>");
while(list($id, $login, $bday) = mysql_fetch_row($result))
{
$month = substr($bday, -4, 2);
$year = substr ($bday, -0, 4);
$age = $cur_year - $year;
if ($month == $time)
{
print ("<a href=\"http://forum_url/index.php?t=usrinfo&id=$id\">$login</a> <span class=\"small\">(<b>$age</b>)</span><br&g t;\n");
}
}
}
?>
Call the function with...
<?php bday(); ?>
I decided to show all birthdays for the current month instead of each day. The code could easily be changed to show birthdays by day.
Have fun!
Heidi
|
|
|
|