TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 728
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 395
  • Total: 395

Looking for Birthday Code

Started by qwe3, March 17, 2006, 05:59:45 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JPDeni

#20
Okay. I think this will do what you want:
global $db_prefix, $scripturl;

$title = date('F') . ' Birthdays';
echo '
<div class="tborder" style="margin-bottom: 5px;">
  <div class="catbg2" style="padding: 4px; font-weight: bold;">';
echo $title;
echo '
  </div>
  <div class="windowbg" style="padding: 4px; ">';
      $month = date('m');
      $month_number = '-' . $month . '-';
      $query = db_query(
    "SELECT ID_MEMBER, memberName, birthdate
     FROM {$db_prefix}members
     WHERE birthdate LIKE '%$month_number%'
     AND birthdate NOT LIKE '0001-01-01'
     ORDER BY memberName", __FILE__, __LINE__);
  if(db_affected_rows() != 0)
  {
    $birthdays = array();
    $member = array();
    while ($row = mysql_fetch_assoc($query))
    {
       $day = substr($row['birthdate'],8,2);
       $birthdays[$row['memberName']] =  $day;
       $member[$row['memberName']] = $row['ID_MEMBER'];
    }
    asort($birthdays);
    foreach ($birthdays as $key => $value)
    {
      echo '<a class="normaltext" href="' . $scripturl . '?action=profile;u=' . $member[$key] . '">' . $key . '</a> (' . $value . '.' . $month . ')<br />';
   }
}
else
  echo 'No birthdays this month';
echo'  </div>
</div> ';

JPDeni

#21
I did another version of this:

  • The dates are in a table (see attached screenshot). I think it looks neater.
  • Uses the title and formatting from the block. It wasn't lining up nicely with the other blocks on the side.
  • Only shows birthdays for those who have logged into the forum within the past year.


Anyway, here's the code. I don't get any errors from it. YMMV.  :)

global $db_prefix, $scripturl;

$last_year = date('U') - (365 * 24 * 60 * 60);
$month = date('m');
$month_number = '-' . $month . '-';
$query = db_query(
    "SELECT ID_MEMBER, memberName, birthdate
     FROM {$db_prefix}members
     WHERE birthdate LIKE '%$month_number%'
     AND birthdate NOT LIKE '0001-01-01'
     AND lastLogin > '$last_year'
     ORDER BY memberName", __FILE__, __LINE__);

if(db_affected_rows() != 0)
{
  $birthdays = array();
  $member = array();
  while ($row = mysql_fetch_assoc($query))
  {
    $day = substr($row['birthdate'],8,2);
    $birthdays[$row['memberName']] =  $day;
    $member[$row['memberName']] = $row['ID_MEMBER'];
  }
  asort($birthdays);
  echo '<table>';
  $yesterday = 0;
  foreach ($birthdays as $key => $value)
  {
    if ($value <> $yesterday)
    {
      if ($yesterday > 0)
        echo '</td></tr>';
      echo '<tr valign="top"><td>' , $value , '</td><td>';
    }
    echo '<a class="normaltext" href="' . $scripturl . '?action=profile;u=' . $member[$key] . '">' . $key . '</a><br />';
    $yesterday = $value;
  }
  echo '</td></tr></table>';
}
else
  echo 'No birthdays this month';

RoarinRow


SMF 2.0 RC3
TP 1.0 beta 5-1
Wordpress 3.0

Gargoyle


Rocket

Awesome, is there a way to limit this to a particular member group or multiple member groups?

rebelrose

Can we add an image to this, like on top of the list?

JPDeni

Rocket, yeah, I'm sure it can be done. Seems like a lot of work for just a list of birthdays. Don't all your members have birthdays? ;)

RebelRose, it would be easy enough to put an image before the list starts. Just put your image tag before echo '<table>';

rebelrose

What code would I use exactly, sorry JPDeni, not great with code but I am trying.

JPDeni

Sorry. :)

Hmmmm. I guess it depends on where your image is. If you always want to use the same image, no matter what theme the user has active, just use

echo '<img src="http://yourdomain.com/url/to/image.gif">';

If the image is in the theme image directories

echo '<img src="', $settings['images_url'], '/image.gif" alt="Happy birthday!" />';
With this second one, you'll also want to change the first line of the code to
global $db_prefix, $scripturl, $settings;

rebelrose

Quote from: JPDeni on October 21, 2006, 07:50:47 PM
Sorry. :)

Hmmmm. I guess it depends on where your image is. If you always want to use the same image, no matter what theme the user has active, just use

echo '<img src="http://yourdomain.com/url/to/image.gif">';

If the image is in the theme image directories

echo '<img src="', $settings['images_url'], '/image.gif" alt="Happy birthday!" />';
With this second one, you'll also want to change the first line of the code to
global $db_prefix, $scripturl, $settings;

Thank you very much.

This website is proudly hosted on Crocweb Cloud Website Hosting.