Stuck on if statements

4 posts by 2 authors in: Forums > CMS Builder
Last Post: December 22, 2012   (RSS)

By Mel - December 22, 2012

Despite reading postings and the cmsbcookbook I still cannot get to grips with the if statement

All of the below works fine it loads and displays records from the database without problem, but what I want to do is if there are no records is to put some text instead i.e

"sorry there are no listings at this present time please visit us again soon"

At the moment when there are no records its just a blank page

But for the life of me I just cannot work out how to do it, what should I be adding  to it?

Thanks Mel

All the code works just fine if there are records

<?php
    // load viewer library
  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
  $dirsToCheck = array('/home/*********/public_html/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

  // load records
  list($biosRecords, $biosMetaData) = getRecords(array(
    'tableName'   => 'bios',
    'where' => 'ne1="1"',
  ));
?>

Below displays thumbnail and link to detail page without problem

<?php foreach ($biosRecords as $biosRecord): ?><!-- start master foreach-->
    <div class="bg-1 bioFrame">      
           <div class="name"><?php echo $biosRecord['name'] ?>&nbsp;&nbsp;</div>
              
 <!-- ....... This section deals with picture ...... -->     
     
   <div align="center" class="img_border"><?php foreach ($biosRecord['newimage'] as $upload): ?>
  <?php if ($upload['isImage']): ?>
          <a href="<?php echo $biosRecord['_link'] ?>" target="_self"><img src="<?php echo get_custom_watermark_url($upload['urlPath'], '110watermarkSmall.png') ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="<?php echo $biosRecord['name'] ?>"></a>
          <?php else: ?>     
          <?php endif ?>
    </div>
    <?php endforeach ?>

     <div align="right"style="padding-top:3px;">
     <a href="<?php echo $biosRecord['_link'] ?>" target="_self">View My Details</a>
     </div>
     
<!-- finish bioFrame--></div>  
   
<!-- finish master foreach--><?php endforeach ?>

By Mel - December 22, 2012

Problem solved found in the CMSB documentation

<?php if (!$my_sectionRecords): ?> No records were found!<br/><br/> <?php endif ?>

Hi Mel,

Sorry I didn't see your post. Glad you solved the issue.

Now you know that you can use the ! to indicate a "not" condition in any if statement.

Best for the holiday season...

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php