<!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>&nbsp;</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-&gt;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>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>Neil</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial></FONT>&nbsp;</DIV>
<DIV><FONT size=2 face=Arial>----- Original Message ----- </FONT>
<DIV><FONT size=2 face=Arial>From: "Ivan Sergio Borgonovo" &lt;</FONT><A 
href="mailto:mail@webthatworks.it"><FONT size=2 
face=Arial>mail@webthatworks.it</FONT></A><FONT size=2 
face=Arial>&gt;</FONT></DIV>
<DIV><FONT size=2 face=Arial>To: &lt;</FONT><A 
href="mailto:support@drupal.org"><FONT size=2 
face=Arial>support@drupal.org</FONT></A><FONT size=2 
face=Arial>&gt;</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>&gt; On Fri, 9 Apr 2010 13:49:43 -0300<BR>&gt; "Neil Coghlan" 
&lt;</FONT><A href="mailto:neil@esl-lounge.com"><FONT size=2 
face=Arial>neil@esl-lounge.com</FONT></A><FONT size=2 face=Arial>&gt; 
wrote:<BR>&gt; <BR>&gt;&gt; I am trying to print the number of downloads a 
user's attachments<BR>&gt;&gt; have produced and am 95% there. I just don't know 
how to print<BR>&gt;&gt; zero if the SUM returns nothing.<BR>&gt; <BR>&gt; I'd 
check why a sum() is returning null before casting in php.<BR>&gt; <BR>&gt; 
sum() is going to return a 0 if NO record was returned.<BR>&gt; That means there 
is at least one count that is null (and some may<BR>&gt; not be), a null in a 
sum is enough to nullify the sum. 10 + null =<BR>&gt; null.<BR>&gt; <BR>&gt; 
select sum(coalesce(count, 0))...<BR>&gt; You'd be better to set default 0 on 
files_download.count and update<BR>&gt; the null record to 0.<BR>&gt; <BR>&gt; 
-- <BR>&gt; Ivan Sergio Borgonovo<BR>&gt; </FONT><A 
href="http://www.webthatworks.it"><FONT size=2 
face=Arial>http://www.webthatworks.it</FONT></A><BR><FONT size=2 face=Arial>&gt; 
<BR>&gt; -- <BR>&gt; [ 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>&gt;</FONT></BODY></HTML>