show birthday

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
sirTemplar
Forum Commoner
Posts: 65
Joined: Wed Dec 18, 2002 1:57 am

show birthday

Post 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! :)
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post 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
f1nutter
Forum Contributor
Posts: 125
Joined: Wed Jun 05, 2002 12:08 pm
Location: London

Post 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!
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Post Reply