As a brief explanation of what I'm trying to do:
I have a MySql database with various columns. One of these columns is the "birthday" column which contains the users date of birth.
What I'm trying to do is take all of the date of births in this column, turn them in to an age, and then work out the average/mean age.
So... I've got the code for both parts working, I just can't get them to work together!
I can feed the birthday function I have a date of birth, and it'll turn it in to an age.
I can get all of the dates of birth in to an array.
What I can't do is anything from here. I can't turn the array in to the ages and work out the mean, basically, and it's driving me nuts. I am a newbie to PHP, but I've done a fair bit of work so far on this.
Would REALLY appreciate help to get this working! I just don't know where to go from the below.
Here's my code:
// Age calculation
function CalculateAge($BirthDate)
{
// Put the year, month and day in separate variables
list($Day, $Month, $Year) = explode("/", $BirthDate);
$YearDiff = date("Y") - $Year;
// If the birthday hasn't arrived yet this year, the person is one year younger
if(date("m") < $Month || (date("m") == $Month && date("d") < $DayDiff))
{
$YearDiff--;
}
return $YearDiff;
}
// How to use the function
// CalculateAge("24/06/1991");
//Birthdate array
$ages = mysql_query("SELECT birthday FROM user_records");
$agearray = array();
while($row=mysql_fetch_assoc($ages)) {array_push($agearray, $row);}
Thanks for any help in advance.