I have a mysql column named time_on_site.
The column is stored as a variable h:m:s
Currently in my code I have the following:
foreach($db->query("SELECT country,siteID,referring_site,COUNT(country)
AS thecount,COUNT(distinct country)
FROM rotator_tracking WHERE siteID='$_GET[site]'
GROUP BY country, referring_site ORDER BY thecount ASC") as $row) {
if (isset($row['referring_site'])) {
echo '
<tr>
<td class="country" style="padding: initial;">
' . $row['referring_site'] . '
</td>';
} else {
echo '
<tr>
<td class="country" style="padding: initial;">
Unknown
</td>';
}
echo '
<td class="country_referral" style="padding: initial;">
' . $row['country'] . '
</td>';
echo '
<td class="country_referral" style="padding: initial;">
' . $row['thecount'] . '
</td>';
echo '
<td class="country_referral" style="padding: initial;">' .
$row['COUNT(distinct country)'] . '
</td>
</tr>';
}
What I am trying to figure out how to do is to add another td that shows an average time on site based on both the country and referring site grouping using the value from time_on_site.
So effectively the table should loop:
referring site : country : total visits : unique visits : average time on site
Because of the date being a variable format, it seems its not as easy to just SUM and divide by total. Help? How should I do this?