When I run the select directly in mysql it returns 2 NULL results and 2 averages. When I try to echo using isset, all values return Null (displayed as "unknown"). When I remove the isset, the two values are returned as well as 2 empty values.
I have also tried to use $row['timesum'] != '0', > '0', != '' No matter how i try to return this it either displays every result as 'unknown' or it won't display any 'unknown'. Am I missing something?
foreach($db->query("
SELECT SEC_TO_TIME( AVG( TIME_TO_SEC( `time_spent` ) ) ) AS timeSum,
local,siteID,referring_site,COUNT(local) AS thecount,
COUNT(distinct local)
FROM rotator_tracking WHERE siteID='43'
GROUP BY local, referring_site
ORDER BY thecount DESC") as $row) {
if (isset($row['timesum'])) {
echo $row['timeSum'];
} else {
echo 'Unknown';
}
}
Here you are setting the function to the alias timeSum (note the capital "S"):
SELECT SEC_TO_TIME( AVG( TIME_TO_SEC( `time_spent` ) ) ) AS timeSum
Here you are referring to it as all lower case:
if (isset($row['timesum'])) {
Be careful, remember that it is case sensitive.