A
Anonymous
Guest
Right can any of you guys spot a mistake.. or perhaps have a better way of doing it.. my current code is:-
<?
mysql_select_db( "phptest" ) or die( mysql_error() );
// get the data from mysql
$result = mysql_query( "SELECT FirstName, DOB FROM test;" );
// set the current dates
$current_day = date("d");
$current_month = date("m");
$current_year = date("Y");
while ($myrow = mysql_fetch_row($result)) {
$name = $myrow[0];
$birthday = $myrow[1];
// set the dob dates
$dob_day = substr($birthday,6,2);
$dob_month = substr($birthday,4,2);
$dob_year = substr($birthday,0,4);
// calculate age
$age = ($current_year - $dob_year) - 1;
if ($dob_month < $current_month) { $age++; }
if ((
// calculate age
$age = ($current_year - $dob_year) - 1;
if ($dob_month < $current_month) { $age++; }
if (($dob_month == $current_month) && ($dob_day <= $current_day)) { $age++; }
print "Age = $age";
}
// finished!
?>
any help would be much appriciated..
<?
mysql_select_db( "phptest" ) or die( mysql_error() );
// get the data from mysql
$result = mysql_query( "SELECT FirstName, DOB FROM test;" );
// set the current dates
$current_day = date("d");
$current_month = date("m");
$current_year = date("Y");
while ($myrow = mysql_fetch_row($result)) {
$name = $myrow[0];
$birthday = $myrow[1];
// set the dob dates
$dob_day = substr($birthday,6,2);
$dob_month = substr($birthday,4,2);
$dob_year = substr($birthday,0,4);
// calculate age
$age = ($current_year - $dob_year) - 1;
if ($dob_month < $current_month) { $age++; }
if ((
// calculate age
$age = ($current_year - $dob_year) - 1;
if ($dob_month < $current_month) { $age++; }
if (($dob_month == $current_month) && ($dob_day <= $current_day)) { $age++; }
print "Age = $age";
}
// finished!
?>
any help would be much appriciated..