display '0' if field exists, but not approved
4 posts by 2 authors in: Forums > CMS Builder
Last Post: February 28, 2011 (RSS)
By Deborah - February 27, 2011
While I can display the total number of approved comments, this total does not reflect '0', because (as I understand it) PHP is is counting only the comments that are approved.
This code successfully displays approved comments:
<?php foreach ($commentsRecords3 as $record): // total number of approved comments ?>
<?php if ($record['status'] == "1"): ?>
<?php $recordsReturned = count ($commentsRecords3); ?>
<p class="subhd">comments (<?php echo ($commentsMetaData['totalRecords']); ?>)</p>
<?php endif ?>
<?php endforeach; ?>
If there are (either comments entered or not entered) no comments approved, I would like to display a default message, such as " Comments (0) ".
My 'elseif' attempts resulted in no text display. Any tips? I feel it is so simple, but the solution eludes me... still learning PHP.
~ Deborah
Re: [Deborah] display '0' if field exists, but not approved
By Dave - February 27, 2011
Try putting an if block below the foreach, like this:
<?php foreach ($commentsRecords3 as $record): // total number of approved comments ?>
<?php if ($record['status'] == "1"): ?>
<?php $recordsReturned = count ($commentsRecords3); ?>
<p class="subhd">comments (<?php echo ($commentsMetaData['totalRecords']); ?>)</p>
<?php endif ?>
<?php endforeach; ?>
<?php if (!$commentsRecords3): ?>
No Comments
<?php endif ?>
Let me know if that works for you. Thanks! :)
interactivetools.com
Re: [Dave] display '0' if field exists, but not approved
By Deborah - February 28, 2011
Thanks for the solution, Dave!
~ Deborah
Re: [Deborah] display '0' if field exists, but not approved
By Dave - February 28, 2011
interactivetools.com