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: [chris] Detect "empty" photo value (again)

By rcrofoot - January 7, 2010

Thanks Chris...Actually what you suggested, is what I already had...But there is a more efficient way to do it...I know the syntax from a former version of cmsBuilder, but I'm trying to implement it in a newer version...Here's what I mean:

In cmsBuilder version v1.09:[/#ff0000]

<?php
$listing_agent=$record['listing_agent'];
require_once "/usr/www/users/decaro/kellyassociates/decaro/cmsAdmin/lib/viewer_functions.php";

$options2 = array(); // NOTE: see online documentation for more details on these options
$options2['tableName'] = 'agents_ka'; // (REQUIRED) MySQL tablename to list record from. Example: "article";
$options2['recordNum'] = ''; // (optional) Record number to display. Example: "1"; Defaults to number on end of url, then 1
$options2['where'] = "full_name='".$listing_agent."'"; // (ADVANCED) MySQL WHERE conditions to use INSTEAD of recordNum to look up record. Example: "fieldname = 'value'"
$record2 = getRecord($options2);
//echo $record2['email'];
?>

<!--load this variable in order to test for no main photo-->
<?php $uploadList = getUploads($options['tableName'], 'main_photo', $record['num']); ?>
<?php if (empty($uploadList)): ?> [/#0080ff](this works in older version)
[/#000000] <img id="mainPix" src="images/photoscomingsoon_450_300.jpg" width="600" height="400" border="0" /><br/>
<?php endif ?>

Now, in v1.33 I'm working with this:[/#ff0080]

<?php

require_once "/usr/www/users/decaroii/cmsAdmin/lib/viewer_functions.php";

list($agentsRecords, $agentsMetaData) = getRecords(array(
'tableName' => 'agents',
'orderBy' => 'lastname ASC',
));
?>

<?php foreach ($agentsRecords as $record): ?>
<?php if (empty($record['agent_image_big']) && $record['bio']=='')
{ ?>
<a href="#" onclick="javascript:alert('<?php echo $record['agent_name'] ?>\'s homepage is currently under construction...');"><?php echo $record['agent_name'] ?></a><br>
[/#008000] <?php
}else if($record['bio']=='').......etc, etc, etc......end foreach loop...

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

Doug had sent me the code for v1.09

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

but I can't get that code to work in 1.33 (changed $options['tableName'] to a few different variations, and substituted the new field in place of 'main_photo' but with no luck)...

Anyway hope that's somewhat clear...Any ideas...

Thanks, Rick

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