I would like to calculate the total number of difference in years. The scenario is as follows: I have a table in a database. It contains details of members including their experience in years. I would like to get the total of experience years. For example The total years of experience of members is 90years. So far i have tried and all i get is the experience of just a single member.
public function getMemberCollectiveExperience() {
global $config;
$db = new DatabaseController($config['db']['hostname'], $config['db']['username'], $config['db']['password'], $config['db']['database']);
$sql = "SELECT * FROM tbl_member WHERE status = 1";
$result = $db->retrieveRecord($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_array()) {
#get member years
$memberYears = $row['personal_experience'];
$currentYear = date('Y');
$firstResult = $currentYear - $memberYears;
$total = $firstResult;
}
$result = array('count' => $total);
}
return $result;
}