This is the query I am using and it is in page 1 not inside the function.

<?php
$sql2= mysql_query("SELECT *
FROM catego WHERE category_id = '$idc'");
$categoryCount = mysql_num_rows($sql2); 
if ($categoryCount>0 )
{
    $row2 = mysql_fetch_array($sql2);     
    $id = $row2["category_id"];


    $birthdate = $row2["birthdate"];
    $address = $row2["address"];
}
?>

Comments

What language are you programming in? EDIT - PHP I see

Written by Peter Hamilton

Why is it formatted in that bizarre way?

possible duplicate of How do I easily determine the age from an birthday? (php)

Written by deceze

possible duplicate of PHP calculate age

Written by Jürgen Thelen

possible duplicate of stackoverflow.com/questions/3845208/…

Written by Peter Hamilton

possible duplicate of stackoverflow.com/questions/2533890/…

Written by Peter Hamilton

Accepted Answer

A simple php function could be something like the following:

function birth_date ($birth_date){
    list($y,$m,$d) = explode(",",$birth_date);
    $y_diff  = date("Y") - $y;
    $m_diff = date("m") - $m;
    $d_diff   = date("d") - $d;
    if ($m_diff < 0 || $d_diff < 0) { $y_diff--; }
    return $y_diff;
}

i.e split on your commas, work out the differences, adjust for which side of their birthdate the day/month is, if so reduce the year by one, then just return the year.

Then in your page you can put:

<li><span class="label">Age:</spa><?php$age = getage($birthdate); echo $age;?> </li>

EDIT:

<?php
function birth_date($birth_date){
    list($y,$m,$d) = explode(",",$birth_date);
    $y_diff  = date("Y") - $y;
    $m_diff = date("m") - $m;
    $d_diff   = date("d") - $d;
    if ($m_diff < 0 || $d_diff < 0) { $y_diff--; }
    return $y_diff;
}

$sql2= mysql_query("SELECT * FROM catego WHERE category_id = '$idc'");
$categoryCount = mysql_num_rows($sql2); 
if ($categoryCount>0 )
{
    $row2 = mysql_fetch_array($sql2);     
    $id = $row2["category_id"];
    $birthdate = $row2["birthdate"];
    $address = $row2["address"];

    $age = birth_date($birthdate);
}
?>
Written by Peter Hamilton
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki