show an img scr= within a foreach loop otherwise no image shown

2 posts by 2 authors in: Forums > CMS Builder
Last Post: October 13, 2010   (RSS)

By Mikey - October 12, 2010 - edited: October 12, 2010

Got it figured out from solution Dave provided on this thread:
http://www.interactivetools.com/iforum/Products_C2/CMS_Builder_F35/gforum.cgi?post=68037;search_string=image%20in%20loop;t=search_engine#68037

I'd like to include the image (documents-download.jpg) within a foreach loop, but I only want the image to appear once at the top of the loop, instead of repeating for each document uploaded. The purpose of having it within the loop is so the (documents-download.jpg) would vanish from the site page if no documents are available.

I chose not to use the upload for placing the image, so that there is no need to upload the image for every site page that has the document download feature... otherwise my client, may forget to upload the image and place it above each uploaded file. With this method, the image is part of the php page and there's nothing further the client needs to do, other than upload their documents.

I've edited this post to include the new code that makes one image appear in the loop:

<div id="documents"><!-- documents -->
<?php foreach ($documentRecord['documents'] as $upload): ?>
<img src="images/documents-download.jpg" alt="documents" />
<?php break; ?>
<?php endforeach ?>

<?php foreach ($documentRecord['documents'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath1'] ?>" alt="" width="<?php echo $upload['thumbWidth1'] ?>" height="<?php echo $upload['thumbHeight1'] ?>" border="0" />

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

<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>"><?php echo $upload['info1'] ?></a><br />
<?php endif ?>

<?php endforeach ?>
<!-- /documents --></div>