Display image or text if no image available

3 posts by 2 authors in: Forums > CMS Builder
Last Post: July 22, 2010   (RSS)

Re: [RapidWeb] Display image or text if no image available

By Jason - July 22, 2010

Hi,

From what I can see on your page, there will at most be one image displayed beside each listing. In that case, we wouldn't want to put all of our logic inside a foreach loop, because if there is no image uploaded, nothing inside the loop will happen. Try this code instead:

<?php foreach ($minyanRecords as $record): ?>
<?php $bgColor = (@$bgColor == '#F8F8F8') ? '#E2FEE9' : '#F8F8F8'; ?>
<tr bgcolor="<?php echo $bgColor ?>" class="tableListingRow">
<td width="114" height="90" align="center" valign="top">
<?php if($record['images']):?>
<?php $upload=$record['images'][0];?>
<?php if($upload['hasThumbnail']): ?>
<a href="<?php echo $record['_link'] ?>"><img src="<?php echo $upload['thumbUrlPath2'] ?>" alt="" width="<?php echo $upload['thumbWidth2'] ?>" height="<?php echo $upload['thumbHeight2'] ?>" hspace="3" align="top" /></a><br/>
<?php else: ?>
<img src="<?php echo $upload['urlPath'] ?>" alt="" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" hspace="3" align="top" /><br/>
<?php endif ?>
<?php else: ?>
No Image Available
<?php endif ?>

</td>


This code first checks to see if a file has been uploaded to the images field. If it has, it outputs the image, otherwise it outputs "No Image Available".

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Display image or text if no image available

By (Deleted User) - July 22, 2010

Thank you!

Works very good!