Testing for "no image" in a page viewer

4 posts by 2 authors in: Forums > CMS Builder
Last Post: February 21, 2008   (RSS)

Re: [rcrofoot] Testing for "no image" in a page viewer

By Dave - February 20, 2008

Hi Rick,

What we can do is just assign the uploads to a variable first, and then you can test if it's empty of not.

Replace this:
<?php foreach (getUploads($options['tableName'], 'main_photo', $record['num']) as $upload): ?>

With this:
<?php $uploadList = getUploads($options['tableName'], 'main_photo', $record['num']); ?>

<?php if (empty($uploadList)): ?>
No uploads for this record!
<?php endif ?>

<?php foreach ($uploadList as $upload): ?>


Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Testing for "no image" in a page viewer

Dave-

Your solution worked perfectly...Why didn't I think of that!

So, my understanding is that in the following inner foreach, any iteration will skip what's inside the loop if there's no contents...in this case an image in the 'main_photo' field...i.e. if ($upload['isImage']): won't even test because the 'main_photo' field is empty...

<?php foreach ($listRows as $record): ?>

<?php foreach (getUploads($options['tableName'], 'main_photo', $record['num']) as $upload): ?>
<?php if ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="255" height="170" border="0" /><br/>
<?php endif ?>
<?php endforeach ?>

<?php endforeach ?>

Thanks again for all the help...Rick

Re: [rcrofoot] Testing for "no image" in a page viewer

By Dave - February 21, 2008

Glad it's working!

And you're right, if there's no images then all the code and html inside the foreach loop will be ignored.
Dave Edis - Senior Developer
interactivetools.com