Detect "empty" photo value (again)

5 posts by 2 authors in: Forums > CMS Builder
Last Post: January 8, 2010   (RSS)

By rcrofoot - January 6, 2010

Hello-

Can you tell me if you see anything wrong with this code (highlighted in red)...It doesn't want to work...Is this not the way to check for the "non-presence" of a photo? Thanks in advance...Rick[/#008080]

<table border="0" rules="none" cellpadding="0" cellspacing="0" style="position:absolute;left:-5px;top:-18px;width:477px;font-family:arial;font-size:12px;font-weight:normal;">

<?php foreach ($listRows as $record): ?>
<?php
if (($record['status'] != 'Inactive') && ($record['status'] != 'Sold'))
{
//add spacing before photo, only if not on first photo
if ($skipPadding == 2){echo '<tr><td style="font-size:6px;">&nbsp;</td></tr>';}
?>
<tr>
<td width="255px">
<a target="_parent" href="http://www.kellyrealestate.com/<?php echo $record['_link'] ?>">
<?php //echo $record['_link'] //testing ?>

<!--THIS DOESN'T WORK AT ALL - start-->
<!--load this variable in order to test for no main photo-->
<?php //$uploadList = getUploads($options['tableName'], 'main_photo', $record['num']); ?>
<?php //if (empty($uploadList)): ?>
<!--<img src="images/photoscomingsoon.jpg" width="255" height="170" border="0" /><br/>-->
<?php //endif ?>
<!--THIS DOESN'T WORK AT ALL - end-->[/#ff0000]

<?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 //echo $upload['urlPath'] //testing?>
<?php endif ?>
<?php endforeach ?>
</a>
</td>
</tr>

<?php endforeach ?>
</table>

Re: [rcrofoot] Detect "empty" photo value (again)

By Chris - January 7, 2010

Hi rcrofoot,

How about something like this instead? (changes in red)

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

<?php if ($noImagesFound): ?>
<img src="images/photoscomingsoon.jpg" width="255" height="170" border="0" /><br/>
<?php endif ?>


That would also catch the case when a record has uploads but none of them are images.

I hope this helps, please let me know if you have any questions.
All the best,
Chris

Re: [rcrofoot] Detect "empty" photo value (again)

By Chris - January 8, 2010

Hi Rick,

I think getUploads() is only necessary if you getRecord() (i.e. load a single record.) The preferred method is to use getRecords() (i.e. load zero or more records) which, by default, will load all uploads.


The code in green above works, but I don't think it's reliable...


It looks perfectly sane to me. What makes you think it's unreliable?
All the best,
Chris

Re: [chris] Detect "empty" photo value (again)

By rcrofoot - January 8, 2010

Hi Chris-

Maybe I'm confused. I thought I had once used this method, or a variation of it, to check for an empty photo value, and it didn't work...but can't recall accurately what I did...The code I sent you seems to be working OK, so thanks for your help...

Rick