I am trying to get this to properly give the average response time for tickets. Similar to what is on vb.com but for the life of me it won't work. Gives me -34613 hours and -14 mins, very annoying.
Here is the function:
PHP Code:
function getResponseTime()
{
global $db, $vbulletin, $hour, $minute;
$result = $db->query_read("SELECT * FROM `" . TABLE_PREFIX . "pl9_support_tickets` ORDER BY tid DESC LIMIT 30");
$ticket_num = $db->num_rows($result);
if($ticket_num > 0)
{
$i = 0;
$seconds = 0;
while ($res = $db->fetch_array($result)){
$query = $db->query_first("SELECT radded FROM `" . TABLE_PREFIX . "pl9_support_replies` WHERE ticket='". $res['tid'] ."' ORDER BY radded ASC LIMIT 1");
$query_num = $db->num_rows($query);
$rep = strtotime($query['radded']);
$tick = strtotime($res['tadded']);
$seconds += ($rep - $tick);
$i++;
}
if($i>0)
{
$avg = $seconds / $i;
}
} else {
$avg = 0;
}
$hour = round($avg/3600);
$resttime = $avg - ($hour*3600);
$minute = round($resttime/60);
return;
}
The way I use it in my script is adding this line:
PHP Code:
$response_time = getResponseTime();
Then in my template I have:
Am I trying to do this wrong? Could someone please provide a proper function that will do this right?
Thanks
Steve