<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.18876">
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT size=2 face=Arial>the file_downloads table only has records of files
that have been downloaded so User A may have created 3 content pages with an
attachment on each, but if they haven't been downloaded, he will have no record
in the file_downloads table.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>that's why it was returning no results...I don't
know enough about mysql to say whether it was actually returning NULL or no
result, but the solution offered by Jamie (<FONT face="Courier New">print (int)
$output->DownloadCount;</FONT>) seems to be working now, with a "0" printed
if a user has no records in the file_downloads table.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>Neil</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>----- Original Message ----- </FONT>
<DIV><FONT size=2 face=Arial>From: "Ivan Sergio Borgonovo" <</FONT><A
href="mailto:mail@webthatworks.it"><FONT size=2
face=Arial>mail@webthatworks.it</FONT></A><FONT size=2
face=Arial>></FONT></DIV>
<DIV><FONT size=2 face=Arial>To: <</FONT><A
href="mailto:support@drupal.org"><FONT size=2
face=Arial>support@drupal.org</FONT></A><FONT size=2
face=Arial>></FONT></DIV>
<DIV><FONT size=2 face=Arial>Sent: Friday, April 09, 2010 2:58 PM</FONT></DIV>
<DIV><FONT size=2 face=Arial>Subject: Re: [support] Printing "0" when a db query
returns nothing</FONT></DIV></DIV>
<DIV><FONT face=Arial><BR><FONT size=2></FONT></FONT></DIV><FONT size=2
face=Arial>> On Fri, 9 Apr 2010 13:49:43 -0300<BR>> "Neil Coghlan"
<</FONT><A href="mailto:neil@esl-lounge.com"><FONT size=2
face=Arial>neil@esl-lounge.com</FONT></A><FONT size=2 face=Arial>>
wrote:<BR>> <BR>>> I am trying to print the number of downloads a
user's attachments<BR>>> have produced and am 95% there. I just don't know
how to print<BR>>> zero if the SUM returns nothing.<BR>> <BR>> I'd
check why a sum() is returning null before casting in php.<BR>> <BR>>
sum() is going to return a 0 if NO record was returned.<BR>> That means there
is at least one count that is null (and some may<BR>> not be), a null in a
sum is enough to nullify the sum. 10 + null =<BR>> null.<BR>> <BR>>
select sum(coalesce(count, 0))...<BR>> You'd be better to set default 0 on
files_download.count and update<BR>> the null record to 0.<BR>> <BR>>
-- <BR>> Ivan Sergio Borgonovo<BR>> </FONT><A
href="http://www.webthatworks.it"><FONT size=2
face=Arial>http://www.webthatworks.it</FONT></A><BR><FONT size=2 face=Arial>>
<BR>> -- <BR>> [ Drupal support list | </FONT><A
href="http://lists.drupal.org/"><FONT size=2
face=Arial>http://lists.drupal.org/</FONT></A><FONT size=2 face=Arial>
]<BR>></FONT></BODY></HTML>