SETTING UP "IF" STATEMENTS FOR NO RECORDS MATCHING A CRITERIA - Apr 1st, 2012


This one plagued me for a while until Jason Sauchuk, a programmer with Interactive Tools came to the rescue.

I had a checkbox field in a multi-record editor and I wanted to be able to output a “no records found with the
checkbox checked” message if there were no records with the checkbox checked.

Here’s what he offered:



<?php $ischeck= 0; ?>
<?php foreach ($e_blast_events_noticeRecords as $record): ?>
<?php if($record['apbc_event']==1) $ischeck=1; ?>
<?php endforeach ?>

<?php if ($ischeck==0) echo "no records found."; ?>



I could have also added:



<?php if ($ischeck==1) echo "records were found."; ?>



In the previous recipe, I was using a "where" statement to restrict which dates are displayed in a group. The code I
used to show only events that had a start date or a reception date in the next 7 days was:



<?php
list($my_tableRecords, $my_tableMetaData) = getRecords(array(
'Table name' => 'my_table',
'where' => '(NOW() + INTERVAL 7 DAY) >= event_reception_date AND event_reception_date >= TIMESTAMP(CURDATE(),
"00:00:00") OR (NOW() + INTERVAL 7 DAY) >= event_start_date AND event_start_date >= TIMESTAMP(CURDATE(), "00:00:00")',
));

?>



If there were no records that met the criteria, I wanted to output the same kind of “no records found” notice.

This was one I should have been able to figure out but I just couldn’t come up with a solution. Again, Jason came to
the rescue. He suggested a simple solution:



<?php if(!$e_blast_events_noticeRecords) echo "No events are opening or have a reception during the next 7 days.";
?>



And



<?php if($e_blast_events_noticeRecords) echo "These events are opening or have a reception during the next 7 days."; ?>




The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service