PHP Code:
$query = mysql_query("SELECT SEC_TO_TIME(AVG(TIMESTAMPDIFF(SECOND, `firstcontactdate`,`dateadded`))) FROM leads WHERE userid = $userid AND firstcontactdate != '0000-00-00 00:00:00'");
$queryresult = mysql_fetch_array($query);
list($hours, $minutes, $seconds)=explode(':', $queryresult[0]);
echo $hours . ' hour' . ($hours!=1?'s':'') . ', '.$minutes . ($minutes!=1?'s':'') . ' and ' . $seconds.' second'.($seconds!=1?'s':'');
The ($seconds!=1?'s':'') bit is kinda the same as if ($seconds != 1) { echo 's'; } else { echo ''; }. It's known as the ternary operator (
it
)

Off Topic:
I'm moving this thread to the PHP forum now
Bookmarks