Hey guys,
I'm trying to build a search feature in my site that will allow an employer to search for a student based on the number of years of work experience they have. There are two categories of work experience: current and previous. So the code is supposed to get the total number of years of work experience for each student (current + previous), based on the work dates they have posted.
So far, I have been able to obtain a piece of code that gets a rough estimate for the number of years between two dates. What I want is for the total number of years to be added and displayed in a table if both the current and previous work experience dates belong to the same student. This is my code so far...
PHP Code:
<?php
$workprevious = mysql_query("Select * from work_experience, students where students.stud_ID = work_experience.stud_ID AND work_type='previous'") or die (mysql_error());
$row_workprevious = mysql_fetch_assoc($workprevious);
$date1 = $row_workprevious['work_date_from'];
$date2 = $row_workprevious['work_date_to'];
$diff = abs(strtotime($date2) - strtotime($date1));
$years = floor($diff / (365*60*60*24));
$workcurrent = mysql_query("Select * from work_experience, students where students.stud_ID = work_experience.stud_ID AND work_type='current'") or die (mysql_error());
$row_workcurrent = mysql_fetch_assoc($workcurrent);
$date3 = $row_workcurrent['work_date_from'];
$date4 = $row_workcurrent['work_date_to'];
$difference = abs(strtotime($date3) - strtotime($date4));
$year = floor($difference / (365*60*60*24));
echo $years;
if ($row_workprevious['stud_ID']==$row_workcurrent['stud_ID']) {
$total = $years + $year;
echo $total;
}
elseif ($row_workprevious['stud_ID']==$row_workcurrent['stud_ID']) {
echo $year;
echo $years;
}
?>
Any assistance would be greatly appreciated as I'm still new in php