I have a table that stores surveying data, when a survey is completed it is recorded with timedate, when the survey is resolved it is also timedate. I am looking to get the average between these two times. I have this to calculate the response times for each entry, but I want to get a customer average. Each customer will have many entries.
function timediff($startTime,$endTime){
//you can modify what the function returns
global $timediff; //global array if you need it
$a = strtotime($endTime) - strtotime($startTime);
$w = $a/3600; //hours.minutes
$h = floor($w);
$ms = $w - floor($w);
$ms = $ms*60; //minutes.seconds
$m = floor($ms);
$s = number_format(($ms - $m)*60);
//basics, declare other parts if needing decimal portions
$timediff['hours']=$h;
$timediff['minutes']=$m;
$timediff['seconds']=$s;
if($h == '0' && $m == '0'){
return "$s Sec";
}elseif($h == '0'){
return "$m Min";
}else{
return "$h Hrs $m Min";
}
}
print"<table border ='1' cellspacing='10'>";
$query = "SELECT * FROM call_data WHERE resolved != '0000-00-00 00:00:00' AND hotspot > '0' AND completed_date >= '2008-12-09' ORDER by dealer";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$completed_datetime = $row["completed_datetime"];
$first_response = $row["first_response"];
$first_response_user_id = $row["first_response_user_id"];
$resolved = $row["resolved"];
$resolved_user_id = $row["resolved_user_id"];
$dealer = $row["dealer"];
$hotspot = $row["hotspot"];
$time4 = timediff($completed_datetime,$first_response);
$time5 = timediff($completed_datetime,$resolved);
if($resolved == $first_response){
$time6 = '';
}else{
$time6 = timediff($first_response,$resolved);
}
$query56 = "SELECT * FROM users WHERE id = '$first_response_user_id'";
$result56 = mysql_query($query56);
while ($row56 = mysql_fetch_array($result56)){
$user_name = $row56['name'];
}
print"<tr>
<td>$dealer</td>
<td>$user_name</td>
<td>$time4</td>
<td>$time5</td>
<td>$time6</td>
<td>$hotspot</td>
</tr>";
}
echo"</table>";
any info would be greatly appreciated. thank you.