 | |  |
 |

rcrofoot
User
Feb 19, 2008, 3:49 PM
Post #1 of 4
(374 views)
Shortcut
|
|
Testing for "no image" in a page viewer
|
Can't Post
|
|
Hi Dave- Regarding the code below to display an image, I noticed that $upload['isImage'] will return the value of 1 if an image has been uploaded by CMS...I need to test for no image to display an alternate photo, so I thought $upload['isImage'] would return 0 if no pix existed, but it doesn't...Can you point me in the right direction to test for no pix...(the code in red is what I've added, but it never gets executed when there's no image)... Thanks, Rick <!-- STEP3: Display Uploads from 'main_photo' (Paste this where you want your uploads displayed) --> <!-- Upload Program Fields : num, createdTime, tableName, fieldName, recordNum, preSaveTempId, filePath, filename, extension, thumbFilePath --> <!-- Upload Image Fields : isImage, hasThumbnail, urlPath, width, height, thumbUrlPath, thumbWidth, thumbHeight --> <!-- Upload Info Fields : info1, info2, info3, info4, info5 --> <?php if ($record): ?> <?php foreach (getUploads($options['tableName'], 'main_photo', $record['num']) as $upload): ?> <?php if ($upload['isImage']): ?> <?php echo "upload['isImage']: ".$upload['isImage']; ?> <img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" /><br/> <?php else: ?> <?php echo 'Add No Main pix here...'; ?><br/> <?php endif ?> <?php endforeach ?> <?php endif ?> <!-- STEP3: /Display Uploads from 'main_photo' -->
|
|
|  |
 |

Dave
Staff
/ Moderator

Feb 20, 2008, 9:59 AM
Post #2 of 4
(359 views)
Shortcut
|
|
Re: [rcrofoot] Testing for "no image" in a page viewer
[In reply to]
|
Can't Post
|
|
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
|
|
|  |
 |

rcrofoot
User
Feb 20, 2008, 5:36 PM
Post #3 of 4
(348 views)
Shortcut
|
|
Re: [Dave] Testing for "no image" in a page viewer
[In reply to]
|
Can't Post
|
|
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
|
|
|  |
 |

Dave
Staff
/ Moderator

Feb 21, 2008, 1:24 PM
Post #4 of 4
(336 views)
Shortcut
|
|
Re: [rcrofoot] Testing for "no image" in a page viewer
[In reply to]
|
Can't Post
|
|
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
|
|
|  |
|