Using an uploaded image in a list

3 posts by 2 authors in: Forums > CMS Builder
Last Post: May 12, 2015   (RSS)

By Damon - May 11, 2015

Hi,

Here is some code to output the rank image for the staff index page:

<?php foreach ($staffRecords as $record): ?>
Record Number: <?php echo htmlencode($record['num']) ?><br/>
Name: <?php echo htmlencode($record['name']) ?><br/>
Rank (value): <?php echo $record['rank'] ?><br/>
<?php $rank = @$record['rank']; ?>
Rank (label): <?php echo $record['rank:label'] ?><br/>

<?php foreach ($rankRecords as $record): ?>
<?php foreach ($record['image'] as $index => $upload): ?>
<?php if($rank == $record['num']) : ?>
<img src="<?php echo htmlencode($upload['thumbUrlPath']) ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>
<?php endif; ?>
<?php endforeach; ?>
<?php endforeach; ?>


<?php endforeach ?>

<?php if (!$staffRecords): ?>
No records were found!<br/><br/>
<?php endif ?>

Make sure at the top of your template your are loading the viewer libraries for both "staff" and "rank".

Inside the "staff" foreach loop, you are first, assigning the rank num to a variable, then using an IF statement to check if it matches the record num in the rank foreachloop. If it does, the image for rank is displayed.

Test this out and see if it works for you. You may have to adjust variable names.

Let me know. Thanks!

Cheers,
Damon Edis - interactivetools.com

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

By northernpenguin - May 12, 2015

Thanks Damon!

That worked perfectly.

--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke