Display image or text if no image available
3 posts by 2 authors in: Forums > CMS Builder
Last Post: July 22, 2010 (RSS)
By (Deleted User) - July 22, 2010
First I want to apologize because this has been discussed already on these boards 1000 times. But I don’t seem to be able to get it right this time around.
I want an image (or just some text saying “No Image Available”) to display in my listing page if there is no image available.
This is my page:
http://www.koshertravelinfo.com/minyan/minyan_listing.php?page=14
This is my code:
I had already tried to add this code:
But when I add that code the page loads completely blank.
Can someone please point out how to fix this?
I want an image (or just some text saying “No Image Available”) to display in my listing page if there is no image available.
This is my page:
http://www.koshertravelinfo.com/minyan/minyan_listing.php?page=14
This is my code:
<?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 foreach ($record['images'] as $upload): ?>
<?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 elseif ($upload['isImage']): ?>
<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 break; ?>
<?php endforeach ?>
</td>
I had already tried to add this code:
<?php else: ?>
No image available
<?php endif ?>
<?php endforeach; ?>
But when I add that code the page loads completely blank.
Can someone please point out how to fix this?
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:
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.
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/
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!
Works very good!