Jump to content

[SOLVED] Age -1 year!!


eaglelegend

Recommended Posts

I have noticed on my site, that users are 1 year younger than what they really are!! take a look at http://www.eaglelegend.com/ - register and look at your profile.

 

here is the code:

<?php



/*



User Profile (user_profile.php)



*/



$rank_check = 1;

$page_title = "User Profile";

include "header.inc.php";



$members = fetch("SELECT * FROM members2 WHERE username = '$user' AND game = '$game'");

$members_profiles = fetch("SELECT * FROM members_profiles2 WHERE username = '$user' AND game = '$game'");



$online = fetch("SELECT last_visit FROM online WHERE userid = '$members[id]' ORDER BY last_visit DESC LIMIT 1");



if ($rank == "7")

{

        $iplog = fetch("SELECT ip_addr FROM ip_log WHERE userid = '$members[id]' ORDER BY id DESC LIMIT 1");

        $membersIP = " ($iplog[ip_addr])";

}

if (!$members[id])

{

        die("$openHTML<p align=center class=error>That is not a real user</p>$closeHTML");

}



if ($members[rank] <= 1)

{

        die("$openHTML<p align=center class=error>This user has been suspended.</p>$closeHTML");

}



$gender = $members_profiles[gender];

$genderArray = array("<img src=images/icons/undecided.gif>", "<img src=images/icons/female.gif>", "<img src=images/icons/male.gif>");

$gender = $genderArray[$gender];



$mailSettings = $members_profiles[mail_settings];

$mailSettingsArray = array(

"<a href=mail_send.php?game=$game&send_to=$usersOn[username]><img src=images/icons/mail.gif></a>",

"<a href=mail_send.php?game=$game&send_to=$usersOn[username]><img src=images/icons/mail.gif></a>",

"");

$mailSettings = $mailSettingsArray[$mailSettings];



$bud = "<a href=buds.php?game=$game&bud=$members[username]><img src=images/icons/bud.gif></a>";



$date_registered = date("M j, Y", $members_profiles[date_registered]);

$last_visited = date("H:i", $online[last_visit]);

$last_visited2 = date("M j, Y @ H:i", $online[last_visit]);



$exBday = explode("-", $members_profiles[birthday]);



$months = array("", "January", "February", "March", "April", "May", "June", "July", "August", "Septemeber", "October", "November", "December");



$bdayMonth = $exBday[0];

if ($bdayMonth < 10) { $bdayMonth = ereg_replace("0", "", $bdayMonth); }



$exBday[0] = $months[$bdayMonth];



$birthday = "$exBday[0] $exBday[1], $exBday[2]";



$userAge = $this_year - $exBday[2];

if ($this_month < $exBday[0])

{

        $userAge = $userAge - 1;

}

if (($this_month == $exBday[0]) AND ($today < $exBday[1]))

{

        $userAge = $userAge - 1;

}



if ($online[last_visit] >= ($timestamp - $secondsToKeepUsersOn))

{

        $onlineNow = "<b><font color=green>Yes! <i><font size=-1>last visit at $last_visited</font></i></font></b>";

}

else

{

        $onlineNow = "<B><font color=red>No <i><font size=-1>last visit on $last_visited2</font></i></font></b></font></b>";

}



$yourNotes = fetch("SELECT bud_note FROM buds2 WHERE bud_me = '$userid' AND bud_you = '$members[id]'");

$yourNotes = $yourNotes[bud_note];

if (!$yourNotes) { $yourNotes = "<i>You do not have any notes on the player, add them to your buddy list to add notes!</i>"; }



$find_shop = fetch("SELECT shop_name,shop_size FROM usershops2 WHERE owner = '$members[id]' AND game = '$game'");

if ($find_shop[shop_name])

{

        $usershop_line = "<b>Shop:</b> <a href=$base_url/usershop.php?game=$game&user=$user>$find_shop[shop_name]</a> <font size=-1>(size $find_shop[shop_size])</font>";

}



$find_gallery = fetch("SELECT gallery_name,gallery_size FROM usergallerys WHERE owner = '$members[id]' AND game = '$game'");

if ($find_gallery[gallery_name])

{

        $gallery_line = "<br><b>Gallery:</b> <a href=$base_url/usergallery.php?game=$game&user=$user>$find_gallery[gallery_name]</a> <font size=-1>(size $find_gallery[gallery_size])</font>";

}



$locationLine = $members_profiles[location];

if (!$locationLine)

{

        $locationLine = "<i>Middle of no where!</i>";

}



$getClub = fetch("SELECT position,club FROM club_members2 WHERE user = '$members[id]' AND game = '$game'");

$getclub = fetch("SELECT id,name FROM clubs2 WHERE id = '$getClub[club]' AND game = '$game'");

if ($getclub[id])

{

        $clubrank = $getClub[position];

        if ($clubrank == 1)

        {

                $position = "Member";

        }

        if ($clubrank == 2)

        {

                $position = "Moderator";

        }

        if ($clubrank == 3)

        {

                $position = "Admin";

        }

        $club_line = "<br><b>Club:</b> $position in <a href=$base_url/club.php?game=$game&clubid=$getclub[id]>$getclub[name]</a>";

}





$findPets = mysql_query("SELECT id,name,level FROM user_pets2 WHERE owner = '$members[id]' AND adoption = '0' AND game = '$game'");

$numUserPets = mysql_num_rows($findPets);

$x = 1;

while ($getPets = mysql_fetch_array($findPets))

{

        if ($x < $numUserPets)

        {

                $petList .= "<a href=user_pets.php?game=$game&id=$getPets[id]>$getPets[name]</a> (Lvl. $getPets[level]), ";

        }

        else

        {

                $petList .= "<a href=user_pets.php?game=$game&id=$getPets[id]>$getPets[name]</a> (Lvl. $getPets[level])";

        }

        $x++;

}



echo <<<END

$openHTML



<table bgcolor=#ffffff width=95%>

<tr><td>

         <CENTER>

END;



echo "<img src='uploads/$members_profiles[avatar_selected]' width=40 height=40> ";



echo <<<END

<FONT SIZE="+2"><B>$members[display_name]'s Profile</B></FONT></CENTER>



         <p>$members_profiles[profile]</p>



         <center><hr width=75% color="$tableOutline"></center>



         <font size=-1>



         <P><b>Username:</b> $members[display_name]$membersIP<br>

                        <b>Real name:</b> $members_profiles[real_name]<bR>

                        <b>Birthday:</b> $birthday ($userAge years old!)<br>

                        <b>Location:</b> $locationLine<br>

                        <b>Date Registered:</b> $date_registered<br>

                        <b>Total Referrals:</b> $members_profiles[referrals]<br>

            <b>Total Posts:</b> $members[post_count]

         </P>



         <P><b>Your Notes:</b> $yourNotes</P>



         <P><b>$numUserPets Pets:</b> $petList</p>



         <P>$usershop_line<br>

         $club_line

         $gallery_line</p>



         <p><b>Online?</b> $onlineNow</P>



                 </font>



<center><table><tr><td>

<form action=mail_send.php?game=$game&send_to=$members[username] method=post>

<input type=submit value="Send Mail">

</form></td><td>

<form action=buds.php?game=$game&bud=$members[username] method=post>

<input type=submit value="Add to Buddy List">

</form></td></tr></table></center>

</td></tr></table>



$closeHTML

END;



?>

Link to comment
Share on other sites

function birthDate($bdate){
  $btime = strtotime($bdate);
  $byear = date('Y',$btime);//birth year
  $bmonth = date('m',$btime);//birth month
  $bday = date('d',$btime);//birth day
  $nyear = date('Y');//this year
  $years = $nyear-$byear;//number of years since birth year
  if (strtotime("$nyear-$bmonth-$bday")>time()){
    $years--;//subtract one year if they haven't had a birthday yet this year
  }
  return $years;
}
echo birthDate('1987-12-01');

Link to comment
Share on other sites

This function can be used to easily return an age in years. Your code:

$exBday = explode("-", $members_profiles[birthday]);
$months = array("", "January", "February", "March", "April", "May", "June", "July", "August", "Septemeber", "October", "November", "December");
$bdayMonth = $exBday[0];
if ($bdayMonth < 10) { $bdayMonth = ereg_replace("0", "", $bdayMonth); }
$exBday[0] = $months[$bdayMonth];
$birthday = "$exBday[0] $exBday[1], $exBday[2]";
$userAge = $this_year - $exBday[2];
if ($this_month < $exBday[0])
{
        $userAge = $userAge - 1;
}
if (($this_month == $exBday[0]) AND ($today < $exBday[1]))
{
        $userAge = $userAge - 1;
}

is overly complicated, and doesn't work. Replace it with this:

function birthDate($bdate){
  $btime = strtotime($bdate);
  $byear = date('Y',$btime);//birth year
  $bmonth = date('m',$btime);//birth month
  $bday = date('d',$btime);//birth day
  $nyear = date('Y');//this year
  $years = $nyear-$byear;//number of years since birth year
  if (strtotime("$nyear-$bmonth-$bday")>time()){
    $years--;//subtract one year if they haven't had a birthday yet this year
  }
  return $years;
}
$userAge = birthDate($members_profiles['birthday']);

 

Also, you should really use quotes for array keys (use $members_profiles['birthday'] instead of $members_profiles[birthday]).

Link to comment
Share on other sites

Why not simply do:

 

$dob = "24-04-1992";

  function calcAge ($dob) {
      $tob = strtotime($dob);
      $age = date('Y') - date('Y', $tob);    
      return date('md') < date('md', $tob) ? $age-1 : $age;
  }

echo calcAge($dob);

 

I cant remember where i saw how to do this but yer its a lot simplar and easier

Link to comment
Share on other sites

So 05-18-1992? Try this:

function birthDate($bdate){
  $btime = strtotime($bdate);
  $byear = date('Y',$btime);//birth year
  $bmonth = date('m',$btime);//birth month
  $bday = date('d',$btime);//birth day
  $nyear = date('Y');//this year
  $years = $nyear-$byear;//number of years since birth year
  if (strtotime("$nyear-$bmonth-$bday")>time()){
    $years--;//subtract one year if they haven't had a birthday yet this year
  }
  return $years;
}
$userAge = birthDate(strftime($members_profiles['birthday'],"%m-%d-%Y"));

Not sure it that will work, because I've never used strftime before, but give it a go.

Link to comment
Share on other sites

Date format;

MM DD YYYY

Code; (edited by f1's code)

<?php



/*



User Profile (user_profile.php)



*/



$rank_check = 1;

$page_title = "User Profile";

include "header.inc.php";



$members = fetch("SELECT * FROM members2 WHERE username = '$user' AND game = '$game'");

$members_profiles = fetch("SELECT * FROM members_profiles2 WHERE username = '$user' AND game = '$game'");



$online = fetch("SELECT last_visit FROM online WHERE userid = '$members[id]' ORDER BY last_visit DESC LIMIT 1");



if ($rank == "7")

{

        $iplog = fetch("SELECT ip_addr FROM ip_log WHERE userid = '$members[id]' ORDER BY id DESC LIMIT 1");

        $membersIP = " ($iplog[ip_addr])";

}

if (!$members[id])

{

        die("$openHTML<p align=center class=error>That is not a real user</p>$closeHTML");

}



if ($members[rank] <= 1)

{

        die("$openHTML<p align=center class=error>This user has been suspended.</p>$closeHTML");

}



$gender = $members_profiles[gender];

$genderArray = array("<img src=images/icons/undecided.gif>", "<img src=images/icons/female.gif>", "<img src=images/icons/male.gif>");

$gender = $genderArray[$gender];



$mailSettings = $members_profiles[mail_settings];

$mailSettingsArray = array(

"<a href=mail_send.php?game=$game&send_to=$usersOn[username]><img src=images/icons/mail.gif></a>",

"<a href=mail_send.php?game=$game&send_to=$usersOn[username]><img src=images/icons/mail.gif></a>",

"");

$mailSettings = $mailSettingsArray[$mailSettings];



$bud = "<a href=buds.php?game=$game&bud=$members[username]><img src=images/icons/bud.gif></a>";



$date_registered = date("M j, Y", $members_profiles[date_registered]);

$last_visited = date("H:i", $online[last_visit]);

$last_visited2 = date("M j, Y @ H:i", $online[last_visit]);



function birthDate($bdate){
  $btime = strtotime($bdate);
  $byear = date('Y',$btime);//birth year
  $bmonth = date('m',$btime);//birth month
  $bday = date('d',$btime);//birth day
  $nyear = date('Y');//this year
  $years = $nyear-$byear;//number of years since birth year
  if (strtotime("$nyear-$bmonth-$bday")>time()){
    $years--;//subtract one year if they haven't had a birthday yet this year
  }
  return $years;
}
$userAge = birthDate(strftime($members_profiles['birthday'],"%m-%d-%Y"));


if ($online[last_visit] >= ($timestamp - $secondsToKeepUsersOn))

{

        $onlineNow = "<b><font color=green>Yes! <i><font size=-1>last visit at $last_visited</font></i></font></b>";

}

else

{

        $onlineNow = "<B><font color=red>No <i><font size=-1>last visit on $last_visited2</font></i></font></b></font></b>";

}



$yourNotes = fetch("SELECT bud_note FROM buds2 WHERE bud_me = '$userid' AND bud_you = '$members[id]'");

$yourNotes = $yourNotes[bud_note];

if (!$yourNotes) { $yourNotes = "<i>You do not have any notes on the player, add them to your buddy list to add notes!</i>"; }



$find_shop = fetch("SELECT shop_name,shop_size FROM usershops2 WHERE owner = '$members[id]' AND game = '$game'");

if ($find_shop[shop_name])

{

        $usershop_line = "<b>Shop:</b> <a href=$base_url/usershop.php?game=$game&user=$user>$find_shop[shop_name]</a> <font size=-1>(size $find_shop[shop_size])</font>";

}



$find_gallery = fetch("SELECT gallery_name,gallery_size FROM usergallerys WHERE owner = '$members[id]' AND game = '$game'");

if ($find_gallery[gallery_name])

{

        $gallery_line = "<br><b>Gallery:</b> <a href=$base_url/usergallery.php?game=$game&user=$user>$find_gallery[gallery_name]</a> <font size=-1>(size $find_gallery[gallery_size])</font>";

}



$locationLine = $members_profiles[location];

if (!$locationLine)

{

        $locationLine = "<i>Middle of no where!</i>";

}



$getClub = fetch("SELECT position,club FROM club_members2 WHERE user = '$members[id]' AND game = '$game'");

$getclub = fetch("SELECT id,name FROM clubs2 WHERE id = '$getClub[club]' AND game = '$game'");

if ($getclub[id])

{

        $clubrank = $getClub[position];

        if ($clubrank == 1)

        {

                $position = "Member";

        }

        if ($clubrank == 2)

        {

                $position = "Moderator";

        }

        if ($clubrank == 3)

        {

                $position = "Admin";

        }

        $club_line = "<br><b>Club:</b> $position in <a href=$base_url/club.php?game=$game&clubid=$getclub[id]>$getclub[name]</a>";

}





$findPets = mysql_query("SELECT id,name,level FROM user_pets2 WHERE owner = '$members[id]' AND adoption = '0' AND game = '$game'");

$numUserPets = mysql_num_rows($findPets);

$x = 1;

while ($getPets = mysql_fetch_array($findPets))

{

        if ($x < $numUserPets)

        {

                $petList .= "<a href=user_pets.php?game=$game&id=$getPets[id]>$getPets[name]</a> (Lvl. $getPets[level]), ";

        }

        else

        {

                $petList .= "<a href=user_pets.php?game=$game&id=$getPets[id]>$getPets[name]</a> (Lvl. $getPets[level])";

        }

        $x++;

}



echo <<<END

$openHTML



<table bgcolor=#ffffff width=95%>

<tr><td>

         <CENTER>

END;



echo "<img src='uploads/$members_profiles[avatar_selected]' width=40 height=40> ";



echo <<<END

<FONT SIZE="+2"><B>$members[display_name]'s Profile</B></FONT></CENTER>



         <p>$members_profiles[profile]</p>



         <center><hr width=75% color="$tableOutline"></center>



         <font size=-1>



         <P><b>Username:</b> $members[display_name]$membersIP<br>

                        <b>Real name:</b> $members_profiles[real_name]<bR>

                        <b>Birthday:</b> $birthday ($userAge years old!)<br>

                        <b>Location:</b> $locationLine<br>

                        <b>Date Registered:</b> $date_registered<br>

                        <b>Total Referrals:</b> $members_profiles[referrals]<br>

            <b>Total Posts:</b> $members[post_count]

         </P>



         <P><b>Your Notes:</b> $yourNotes</P>



         <P><b>$numUserPets Pets:</b> $petList</p>



         <P>$usershop_line<br>

         $club_line

         $gallery_line</p>



         <p><b>Online?</b> $onlineNow</P>



                 </font>



<center><table><tr><td>

<form action=mail_send.php?game=$game&send_to=$members[username] method=post>

<input type=submit value="Send Mail">

</form></td><td>

<form action=buds.php?game=$game&bud=$members[username] method=post>

<input type=submit value="Add to Buddy List">

</form></td></tr></table></center>

</td></tr></table>



$closeHTML

END;



?>

Link to comment
Share on other sites

It's your DB. You said this:

...however if it is helpful to you, perhaps it may be be good to try it DD MM YYYY?...

To me, that says that you have control over it. If it is in the DB as a "date," then you should be able to extract it from the DB table in the proper format.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.