this seems to work!!
thanks Jamie and to everyone else for lending a hand.
Neil ----- Original Message ----- From: Jamie Holly To: support@drupal.org Sent: Friday, April 09, 2010 2:18 PM Subject: Re: [support] Printing "0" when a db query returns nothing
Cast it as an integer:
print (int) $output->DownloadCount;
Jamie Holly http://www.intoxination.net http://www.hollyit.net On 4/9/2010 12:49 PM, Neil Coghlan 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.
here's what I have so far (with download count module installed which creates file_downloads table)
<?php $query= "SELECT SUM(count) AS DownloadCount FROM upload JOIN files ON upload.fid = files.fid JOIN file_downloads ON files.filepath = CONCAT( 'sites/default/files/', file_downloads.filename ) WHERE (files.uid = $account->uid)"; $results = db_query($query); while($output = db_fetch_object($results)){ print $output->DownloadCount; } ?>
works perfectly for those whose content have created downloads. For those who haven't, the result is a blank space. How can I print a nice fat "0"??
regards
Neil
------------------------------------------------------------------------------
-- [ Drupal support list | http://lists.drupal.org/ ]