If NO ENTRY - DISPLAY THIS

3 posts by 2 authors in: Forums > CMS Builder
Last Post: January 18, 2019   (RSS)

By daniel - January 18, 2019

Hi Tina,

Fortunately yes, the solution is fairly simple! The main thing is you'll want to check outside of the loop to see if it contains any of the elements you're looking for, rather than inside of the loop. For your current setup, I'd recommend something along the following lines:

<!-- JOBLIST -->
<h2>JOBS IN MILES CITY, MT</h2>
<?php $foundJob = false; ?>
<?php foreach ($careers_listRecords as $record): ?>
<?php if ($record['job_status'] == 'Active'): ?>
<?php if (strpos($record['job_location'],"\tMiles City MT\t") !== false) : ?>
	<?php $foundJob = true; ?>
	
	<div class="alert alert-info">
	<strong><a href="<?php echo $record['_link'] ?>"><?php echo htmlencode($record['title']) ?></a></strong> &nbsp;<a href="<?php echo $record['_link'] ?>"> <i class="icon-line-minus"></i> Job Details <i class="icon-hand-up"></i> </a>
	</div>
						
					
<?php endif; ?>
<?php endif ?>
<?php endforeach ?>

<?php if (!$foundJob): ?>
  No current listings for this location
<?php endif; ?>

The basic idea is to create a new variable before the loop and set it to false, then sets it to true any time the list outputs a job. Then after the loop, you can check if the variable is true or false, which will let you know if any jobs were output for that location. Just remember to set the variable back to false before each loop.

Hope that helps; let me know if you have any questions!

Thanks,

Daniel
Technical Lead
interactivetools.com

By csdesign - January 18, 2019

Thanks Daniel! It worked like a charm! Thank you also for explaining it!  Have a great day! Tina