Hiding graphics in between fields if fields are empty

3 posts by 2 authors in: Forums > CMS Builder
Last Post: February 13, 2009   (RSS)

By zaba - February 11, 2009

Hi,
I have a record pulled from a database that contains many fields, dividing groups of these fields is a horizontal rule (this is on the page not in the cms). When their is no content in these fileds I don't want the rule to show, as you end up with a pile of rules at the bottom of the page or a double rule where the particular group of fields content is empty.

<?php

require_once "/home/16410/zaba-ponderosa/www.ponderosa-park.co.uk/public_html/cms/lib/viewer_functions.php";

list($lk_funceventsRecords, $lk_funceventsMetaData) = getRecords(array(
'tableName' => 'lk_funcevents',
'allowSearch' => '0',
'where' => 'category="function" AND navigation_title="Weddings"',
));

?>
<!-- Start page -->
<div id="page">
<div class="pagerule">
</div> <!--x pagerule -->
<?php foreach ($lk_funceventsRecords as $record): ?>

<!--This is the first block of fields followed by a rule -->
<h1><?php echo $record['page_title'] ?></h1>
<h2><?php echo $record['sub_head_one'] ?></h2>
<?php foreach ($record['upload_1'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />

<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" />

<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>"><img src="/lakeside/gfx/viewmenu2.gif" alt="<?php echo $upload['filename'] ?>" width="106" height="12" class="viewmenuimg" /></a>

<?php endif ?><?php endforeach ?>
<?php echo $record['sub_text_one'] ?>
<div class="clearthefloats">
</div><!--x clearthefloats -->
<div class="pagerule">
</div><!--x pagerule -->

<!--This is the second block of fields followed by a rule -->

<h2><?php echo $record['sub_head_two'] ?></h2>
<?php foreach ($record['upload_two'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />

<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" />

<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>"><img src="/lakeside/gfx/viewmenu2.gif" alt="<?php echo $upload['filename'] ?>" width="106" height="12" class="viewmenuimg" /></a>

<?php endif ?><?php endforeach ?>
<?php echo $record['sub_text_two'] ?>
<div class="clearthefloats">
</div><!--x clearthefloats -->
<div class="pagerule">
</div><!--x pagerule -->
<!--This is the third block of fields followed by a rule -->

<h2><?php echo $record['sub_head_three'] ?></h2>
<?php foreach ($record['upload_three'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />

<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" />

<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>"><img src="/lakeside/gfx/viewmenu2.gif" alt="<?php echo $upload['filename'] ?>" width="106" height="12" class="viewmenuimg" /></a>

<?php endif ?><?php endforeach ?>
<?php echo $record['sub_text_three'] ?>
<div class="clearthefloats">
</div><!--x clearthefloats -->
<div class="pagerule">
</div><!--x pagerule -->

<!--continues the same totalling 8 blocks -->

<?php endforeach ?>
</div>
<!--x page -->
anyone have any ideas?

Re: [zaba] Hiding graphics in between fields if fields are empty

By Dave - February 11, 2009

Hi zaba,

You can use a PHP if statement to test if the field has any content and only show the html and rule if there is content in the field. Like this:

<?php if ($record['sub_head_three']): ?>
.. show fields and rule here ...
<?php endif ?>

Try adding the if and endif tags around the content you want shown or hidden and change the fieldname in the if to be the field you want to test.

Let me know if that works for you!
Dave Edis - Senior Developer
interactivetools.com