No records in category

4 posts by 2 authors in: Forums > CMS Builder
Last Post: January 11, 2010   (RSS)

By MRI - January 8, 2010

Ok.. I have a listing for hotels.. in the CMS when you add a hotel, you select from a pre determined list for that hotels location.

So on the website I have all the hotels listed and categorized by location using:
<?php if (strpos($record['location'], 'Ham Lake')): ?>

Now i need a solution to display the "No Records Found" if there are no records for that current location.
This doesnt work because its looking at ALL records not just ones labeled with the category location:
<?php if (!$hotel_listingsRecords): ?>
No records were found!<br/><br/>
<?php endif ?>

So im assuming its just tweaking this line... but I cant figure it out:
<?php if (!$hotel_listingsRecords): ?>

Re: [MRI] No records in category

By Chris - January 8, 2010

Hi MRI,

Can you please attach the complete PHP source code for your page?
All the best,
Chris

Re: [MRI] No records in category

By Chris - January 11, 2010

Hi MRI,

Since you're already counting matching records (for your table columns code,) you need only check if $count is 0 after your foreach: (new code in red)

<?php $count = 0; ?>
<?php foreach ($hotel_listingsRecords as $record): ?>
<?php if (strpos($record['location'], 'Coon Rapids')): ?>

<td align="left" valign="top" class="hotel_othercol">

<?php foreach ($record['logo'] as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" />
<?php endforeach ?>

<h5><?php echo $record['hotel_name'] ?></h5>
<?php echo $record['details'] ?></td>

<?php $maxCols=2; if (@++$count % $maxCols == 0): ?>
</tr>
<tr>
<?php endif; ?>

<?php endif ?>
<?php endforeach; ?>

<?php if ($count == 0): ?>
<td colspan="2">No Records Found</td>
<?php endif ?>


You'll want to add this after each of your foreach loops for records.

I hope this helps! Please let me know if you have any questions.
All the best,
Chris