1
m0nty
using functions.php & setting smarty variable
  • 2005/6/21 18:54

  • m0nty

  • XOOPS is my life!

  • Posts: 3337

  • Since: 2003/10/24


i've added a function to calculate someone's age from the MySQL date format.

in functions.php added:

function CalcAge($date_of_birth) { // YYYY-MM-DD
       
$cur_year=date("Y");
       
$cur_month=date("m");
       
$cur_day=date("d");            

       
$dob_year=substr($date_of_birth04);
       
$dob_month=substr($date_of_birth52);
       
$dob_day=substr($date_of_birth82);            
       
       if(
$cur_month>$dob_month || ($dob_month==$cur_month && $cur_day>=$dob_day) )
           return 
$cur_year-$dob_year;
       else
           return 
$cur_year-$dob_year-1;
   }


so what i want now is for the age to be displayed on userinfo.php instead of the date of birth.

in userinfo.php i have the following >

$xoopsTpl->assign('user_birth'$thisUser->getVar('user_birth'));


which gets the date of birth value ok, and i then use the smarty tag <{user_birth}> in the template to display date of birth.

but what i want is to use the age calculation function that i added to functions.php and instead of showing date of birth, i want it to show the result of the calculation as AGE..

so then possibly have

$xoopsTpl->assign('user_age'$thisUser->getVar('user_age'));


in the template and user_age being the result of the calculation..

can any1 help with this?

2
Mithrandir
Re: using functions.php & setting smarty variable

$xoopsTpl->assign('user_age'CalcAge($thisUser->getVar('user_age')));

?

3
m0nty
Re: using functions.php & setting smarty variable
  • 2005/6/21 19:05

  • m0nty

  • XOOPS is my life!

  • Posts: 3337

  • Since: 2003/10/24


hmmm..

not exactly sure on that, as where do i actually tell calcage function to calcualte user_birth and give result as user_age?

4
m0nty
Re: using functions.php & setting smarty variable
  • 2005/6/21 19:10

  • m0nty

  • XOOPS is my life!

  • Posts: 3337

  • Since: 2003/10/24


ok never mind (had to edit your code slightly) :)

$xoopsTpl->assign('user_age'CalcAge($thisUser->getVar('user_birth')));


worked

thanks a lot mith finally starting to learn at least something.. lol

Login

Who's Online

480 user(s) are online (357 user(s) are browsing Support Forums)


Members: 0


Guests: 480


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits