Detect "empty" photo value (again)

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

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

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