Detect "empty" photo value

6 posts by 4 authors in: Forums > CMS Builder
Last Post: November 17, 2009   (RSS)

Re: [rcrofoot] Detect "empty" photo value

By Donna - November 16, 2009

Hi Rick!

Try something like this:

<?php $upload = @$record['photos'][0] ?>

<?php if ($upload): ?>
show upload
<?php endif ?>

<?php if (!$upload): ?>
show no upload image
<?php endif ?>

Give that a try and let me know how it works. :)
Donna

--
support@interactivetools.com

Re: [Donna] Detect "empty" photo value

Thanks Donna...That worked beautifully!

Rick

Re: [Donna] Detect "empty" photo value

Hi Donna-

Thanks again for the solution. I should have asked yesterday why your solution worked and mine didn't.

Here's yours:

[font "Verdana"]<?php $upload = @$record['photos'][0] ?>
<?php if ($upload): ?>


Here's mine:

[font "Verdana"]<?php foreach ($record['photos'] as $upload): ?>
<?php if ($upload['isImage']): ?>



Does it have something to do with NULL vs. EMPTY values...

Thanks, Rick

Re: [rcrofoot] Detect "empty" photo value

By Damon - November 17, 2009

Hi Rick,

There is a number of ways to code this up. This is the way I usually do it:

<?php foreach ($gallery['photos'] as $photos): ?>
<?php if ($photos['isImage']): ?>
...insert code here to display image..
<?php endif; ?>
<?php endforeach ?>

<?php if (!$gallery['photos']): ?>
No images available.
<?php endif; ?>


Does that help?
Cheers,
Damon Edis - interactivetools.com

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

Re: [rcrofoot] Detect "empty" photo value

By Dave - November 17, 2009

>I should have asked yesterday why your solution worked and mine didn't.

It's because the foreach loop loops over all the images, but if there are no images it doesn't loop at all and no code inside it gets run.

So your code that displays "Sorry no images" needs to be outside the foreach loop.

Let me know if that makes sense.
Dave Edis - Senior Developer
interactivetools.com