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.
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 (print (int)
$output->DownloadCount;) seems to be working now, with a "0" printed
if a user has no records in the file_downloads table.
Neil
----- Original Message -----
Sent: Friday, April 09, 2010 2:58 PM
Subject: Re: [support] Printing "0" when a db query
returns nothing
> On Fri, 9 Apr 2010 13:49:43 -0300
> "Neil Coghlan"
<neil@esl-lounge.com>
wrote:
>
>> I am trying to print the number of downloads a
user's attachments
>> have produced and am 95% there. I just don't know
how to print
>> zero if the SUM returns nothing.
>
> I'd
check why a sum() is returning null before casting in php.
>
>
sum() is going to return a 0 if NO record was returned.
> That means there
is at least one count that is null (and some may
> not be), a null in a
sum is enough to nullify the sum. 10 + null =
> null.
>
>
select sum(coalesce(count, 0))...
> You'd be better to set default 0 on
files_download.count and update
> the null record to 0.
>
>
--
> Ivan Sergio Borgonovo
> http://www.webthatworks.it
>
> --
> [ Drupal support list | http://lists.drupal.org/
]
>