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!
show birthday
Moderator: General Moderators
-
sirTemplar
- Forum Commoner
- Posts: 65
- Joined: Wed Dec 18, 2002 1:57 am
show birthday
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!
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!
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.
Enjoy!
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)
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK