[support] Printing "0" when a db query returns nothing

Neil Coghlan neil at esl-lounge.com
Fri Apr 9 17:21:52 UTC 2010


this has the same problem as the first solution suggested...people with 5 downloads are now shown as having 50. People without any downloads correctly have 0.
  ----- Original Message ----- 
  From: sivaji j.g 
  To: support at drupal.org 
  Sent: Friday, April 09, 2010 2:06 PM
  Subject: Re: [support] Printing "0" when a db query returns nothing





  On Fri, Apr 9, 2010 at 10:19 PM, Neil Coghlan <neil at 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.

    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;


  print (is_int($output->DownloadCount) && (int) $output->DownloadCount > 0) ? $output->DownloadCount : NICE_FAT_ZERO;
   

    }
    ?>

    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"??





  -- 
  Thanks
  Sivaji



------------------------------------------------------------------------------


  -- 
  [ Drupal support list | http://lists.drupal.org/ ]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20100409/30f45f57/attachment.html 


More information about the support mailing list