This topic is locked
[SOLVED]

 Display 0 when count result gets nothing

9/24/2014 6:28:24 AM
PHPRunner General questions
S
snuffi01 author

Hi,

I have an PHP ode snippet in an dashboard witch counts rows with an select, problem is when the result is no rows at all then i dont get 0 diplayed as i would like.

Is there any way around this?
PHP Code:

$rstmp = CustomQuery("SELECT

COUNT(call.CallID) AS callstoday

FROM call

INNER JOIN queuecall ON call.CallID = queuecall.CallID

WHERE (queuecall.QueueDN =6610) AND (call.WorkgroupCall =1) AND (DATE(call.StartTime) = DATE(NOW()))

GROUP BY call.WorkgroupCall

ORDER BY DATE(call.StartTime) DESC

");

if ($datatmp = db_fetch_array($rstmp))

echo $datatmp["callstoday)"];

A
Anapolis 9/24/2014

How about changing that to something like this ... where you finish telling PHP what to do if there is no data returned on the count.

Obviously your code does not produce the number 0 when it returns with no results ... but an empty result.
So you have to "spell it out" for PHP what to echo in such cases where there is no result, no 0, when the count turns up with no result.. not even a 1.


$rstmp = CustomQuery("SELECT

COUNT(`call`.CallID) AS callstoday

FROM `call`

INNER JOIN queuecall ON `call`.CallID = queuecall.CallID

WHERE (queuecall.QueueDN =6610) AND (`call`.WorkgroupCall =1) AND (DATE(`call`.StartTime) = DATE(NOW()))

GROUP BY `call`.WorkgroupCall

ORDER BY DATE(`call`.StartTime) DESC

");

if ($datatmp = db_fetch_array($rstmp))

{

echo $datatmp["callstoday)"];

}

else
{

echo '0';

}


I haven't checked this out in a PHPRunner application yet.

S
snuffi01 author 9/24/2014

Thanks!
That works just perfect!