Using an uploaded image in a list

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

By northernpenguin - May 8, 2015 - edited: May 11, 2015

Hi everyone

I have two multiple record editors, one called "staff" which lists all the staff and one called "rank" which the the ranks available.  The rank editor only has two fields, Rank & Image.  The staff editor has a field which is a list and is related to the rank editor.  The concept is that when a new staff record is created, you pick a rank from the list and the image is used.  Unfortunately that doesn't work.  I get the error in CMSB "There was an error creating the list field 'test'. MySQL Error: Unknown column 'upload' in 'field list' "

Is there any way to do this?  I'm stumped!

--
northernpenguin
Northern Penguin Technologies

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

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/