age calc

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

age calc

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you're not calling it with those two arguments... what's the problem?
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post by pinehead18 »

Those aruguements are set...
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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>';
?>
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post 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
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Please fix using PHP Tags. Its much easier to read.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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]
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post 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
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
pinehead18
Forum Contributor
Posts: 329
Joined: Thu Jul 31, 2003 9:20 pm

Post by pinehead18 »

can month = january or doe sit have to = 1 ?
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Work with the [php_man]date[/php_man] function this will help.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the way you are using it, it'd have to be numeric.. or at least, translated into a numeric.
Post Reply