Page 1 of 1

age calc

Posted: Wed Aug 04, 2004 12:58 pm
by pinehead18

Code: Select all

<?php
function checkCurAge($year,$month,$day='') {
        
 $day=(empty($day))?'1':$day;

 list($this_year, $this_month, $this_day) = explode(' ',date('Y n j'));
 $age = $this_year - $year;
 
if($this_month<=$month && ($this_month==$month || $this_day<$day)) {

    $age--;
 }

 return $age;
  
}


?>
This is my code and i get

Warning: Missing argument 1 for checkcurage()
and Warning: Missing argument 2 for checkcurage()

thank you
anthony

Posted: Wed Aug 04, 2004 1:03 pm
by feyd
you're not calling it with those two arguments... what's the problem?

Posted: Wed Aug 04, 2004 2:03 pm
by pinehead18
Those aruguements are set...

Posted: Wed Aug 04, 2004 2:04 pm
by hawleyjr
Post the rest of your code and put this in your function:

Code: Select all

<?php
echo '<PRE>'; print_r(func_get_args ()); echo '</PRE>';
?>

Posted: Thu Aug 05, 2004 2:40 pm
by pinehead18
Question is did i enter that code in the right spot?


function checkCurAge($year,$month,$day='') {

echo '<PRE>'; print_r(func_get_args ()); echo '</PRE>';


$day=(empty($day))?'1':$day;

list($this_year, $this_month, $this_day) = explode(' ',date('Y n j'));
$age = $this_year - $year;

if($this_month<=$month && ($this_month==$month || $this_day<$day)) {

$age--;
}

return $age;

}

That is the code

Warning: Missing argument 1 for checkcurage() in /home/pinehead/www/myprofile on line 81

Warning: Missing argument 2 for checkcurage() in /home/pinehead/www/myprofile on line 81

Array
(
)



that is the output.

Thank you
Anthony

Posted: Thu Aug 05, 2004 2:42 pm
by hawleyjr
Please fix using PHP Tags. Its much easier to read.

Posted: Thu Aug 05, 2004 2:44 pm
by hawleyjr
Also, show us your code that is calling the function. You are not passing any variables to the function. If you were it would show up in the [php_man]print_r[/php_man]

Posted: Thu Aug 05, 2004 3:00 pm
by pinehead18
That is probably the problem becuase i am setting the vars above the function, but i guess the function can't work unless the vars in the function call.

Newb! i am

Posted: Thu Aug 05, 2004 3:01 pm
by pinehead18

Code: Select all

<?php
$month = $get_age[0];
$day = $get_age[1];
$year = $get_age[2];
         
function checkCurAge($year,$month,$day='') {
        
echo '<PRE>'; print_r(func_get_args ()); echo '</PRE>';

 $day=(empty($day))?'1':$day;
 
 list($this_year, $this_month, $this_day) = explode(' ',date('Y n j'));
 $age = $this_year - $year;
 
if($this_month<=$month && ($this_month==$month || $this_day<$day)) {

    $age--;
 }
  
 return $age;
 
}
 
checkCurAge($month,$date,$year);
?>
That is my code.

This is my output on the page.

Array
(
[0] => march
[1] =>
[2] => 1986
)



Thank you
Anthony

Posted: Thu Aug 05, 2004 3:41 pm
by feyd
you didn't set $date now.. and is that the right order of arguments? your functions arguments are in a different order than your passing of variables..

Posted: Thu Aug 05, 2004 4:06 pm
by pinehead18
can month = january or doe sit have to = 1 ?

Posted: Thu Aug 05, 2004 4:08 pm
by hawleyjr
Work with the [php_man]date[/php_man] function this will help.

Posted: Thu Aug 05, 2004 4:10 pm
by feyd
the way you are using it, it'd have to be numeric.. or at least, translated into a numeric.