Page 1 of 1
show birthday
Posted: Wed Jan 08, 2003 9:46 am
by sirTemplar
hello again.
i have a table with a birthday field (date format yyyy-mm-dd). i would like to create a page that would output all the persons having their birthday on the current date (eg. today). what syntax do i have to use? thanks again!

Posted: Wed Jan 08, 2003 11:47 am
by BDKR
Hey,
If you are using MySQL, there is a chapter in the manual that covers stuff very similar to this. Check it out.
Otherwise, do a google search for tutorial topics along these lines.
Cheers,
BDKR
Posted: Wed Jan 08, 2003 12:51 pm
by f1nutter
Done such a thing on my site (its in the top left). By placing everything inside an if statement it can gracefully handle days if no-one has a birthday today. It prints the year that the person was born on, if their birthday is today. Theres also scope for adding style.
Code: Select all
<?php
require_once('$DBCONNECT');
$query = 'SELECT person, DATE_FORMAT(date_of_birth_column, ''%Y'') AS BYear
FROM birthday_table
WHERE DATE_FORMAT(CURRENT_DATE, ''%e %c'') = DATE_FORMAT(date_of_birth_column, ''%e %c'')
ORDER BY BYear';
$result = mysql_query($query, $connection)
or die("Cannot complete query - Birthdays<br>" .mysql_error());
$num_rows = 0;
$num_rows = mysql_num_rows($result);
if ($num_rows > 0)
{
?>
<table width="100%" cellpadding=0 cellspacing=5 border=0>
<tr>
<td class="sidebar">
<table width="100%" cellpadding=2 cellspacing=0 border=0>
<tr>
<td class="sidebar_title"><?php print('Birthdays'); ?></td>
</tr>
<tr>
<td>
<table width="100%" cellpadding=1 cellspacing=0>
<?php
while ($row = @mysql_fetch_assoc($result))
{
?>
<tr>
<td class="small"><?php print($row['person']); ?></td>
<td class="small" align="right"><?php print($row['BYear']); ?></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?php
} // close if ($num_rows > 0)
?>
Enjoy!
Posted: Thu Jan 09, 2003 2:31 am
by twigletmac