display '0' if field exists, but not approved

4 posts by 2 authors in: Forums > CMS Builder
Last Post: February 28, 2011   (RSS)

A client's blog page contains a comments form with posts that are moderated by the admin. For posts that are approved, we are displaying the total number of approved comments, such as " Comments (5) ".

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: [Dave] display '0' if field exists, but not approved

Aha! I had tried an elseif, which didn't do the job.

Thanks for the solution, Dave!

~ Deborah

Re: [Deborah] display '0' if field exists, but not approved

By Dave - February 28, 2011

Glad to help! :)
Dave Edis - Senior Developer
interactivetools.com