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: 629
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 466
  • Total: 466

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.

manji


stormlrd



]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 lastLogin > '$last_year'   AND birthdate <> '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);  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 'Não há aniversários este mês';


its ugly but that should work it just kills any birthday that is jan 1 0001



JPDeni

I realized only today what the problem is. Sorry.

When they upgraded to SMF 1.1, they changed the structure of the birthdays. It used to be 0004-00-00, but they changed it to 0001-01-01. And without telling me first. The nerve! :)

Anyway, I've gone through all of the instances of my code in this topic and added the necessary line to make it work right.

scotte44

I like this block, thanks for sharing. Currently it looks like this:
08 Scott
if Scott's birthday is the 8th of the month. How hard would it be to get it to look like this?
8th Scott (42)
Showing the persons age in parens.

JPDeni

Sorry for taking so long to answer your question, scott. I got your answer, though.


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'];
    $year = substr($row['birthdate'],0,4);
    if ($year <> '0001' && $year <> '0004')
    {
      $age[$row['memberName']] = date('Y') - $year;
      $age[$row['memberName']] = '(' . $age[$row['memberName']] . ')';
    }
    else
      $age[$row['memberName']] = '';
  }
  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> ' . $age[$key] . '<br />';
    $yesterday = $value;
  }
  echo '</td></tr></table>';
}
else
  echo 'No birthdays this month';


I didn't do the "8th" thing, though. Having "8th" instead of "08" is really easy, but it starts to get a bit more complicated when you have to think about "st" and "nd" and "rd." I haven't delved enough into the date functions to know how much I can get php to do for me on that. I don't suppose it would be too hard to just eliminate the opening 0s, if you'd like to do that.

scotte44


brianjw

Instead of "MONTH" Birthdays as the title

I made it say Birthdays in "MONTH"

(you can make it say whatever you want)

You are going to have to modify the line in your bday block which is:
$title = date('F') . ' Birthdays';
change to
$title = 'Birthdays in ' . date('F');
If you follow the steps right and see where i am going with this you will know how to make it say anything you want. Like it could say
"MONTH" Gangsters lol. :2funny: i wouldnt make it that but thats an example :) ;)

brianjw

I want my bday block (IF POSSIBLE ;))
I want to keep the layout:
global $db_prefix, $scripturl;

$title = 'Birthdays in ' . date('F');
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> ';

Except I would like the birthdays to be displayed like:

Brianjw (AGE HERE)
Bob (AGE HERE)
etc. etc.

JPDeni

The display you want is, basically, the last code I gave, except that it also gives the date of the month that the birthday is. It's a little silly, I think, to say "Bob has a birthday some day this month and is going to be 23 years old."

Sledge HaMMeR

@JPDeni: Nice block you've created. But is it possible to show not all birthdays for the month, but just the ones for (let's say) the next 10 days ? That would be great  :coolsmiley:

This website is proudly hosted on Crocweb Cloud Website Hosting.