DISPLAY A SPECIFIC IMAGE FROM A SPECIFIC RECORD - Jun 14th, 2013


My client wanted to be able to display a specific image from a group of records and multi image uploads.

I couldn’t get this to work until Chris Waddell from Interactive Tools unlocked the secret.

He said:

If $affiliationsRecords is a list of all your records, then $affiliationsRecords[0] will give you the first record,
$affiliationsRecords[1] will give you the second, etc. It's a little confusing that the counting starts at 0 instead of
1.

$affiliationsRecords[3]['logo'][2] will grab the fourth record ([3]), its list of images (['logo']), and select its
third image ([2]).

Since $affiliationsRecords[1]['logo'] refers to the list of images. You need to use $affiliationsRecords[1]['logo'][0]
if you want to refer to a specific image ([0] gives you the first one, etc.)

You’ll need to define a variable for the specific image. To call the 3rd image from the 4th record I used



<?php $myImage = $affiliationsRecords[3]['logo'][2]; ?>



The code that you’d use in the body of your viewer page where you want the image to display would be:



<?php $myImage = $affiliationsRecords[3]['logo'][2]; ?>
<img src="<?php echo $myImage['thumbUrlPath'] ?>" width="<?php echo $myImage['thumbWidth'] ?>" height="<?php echo
$myImage['thumbHeight'] ?>" alt="" />



You can also define other variables, like this one for the link to a detail page relating to the same record:



<?php @$mylink = $affiliationsRecords[4]['_link']; ?>



Then the code including a linked image might look like this:



<?php @$myImage = $affiliationsRecords[3]['logo'][2]; ?>
<?php @$mylink = $affiliationsRecords[3]['_link']; ?>
<a href="<?php echo $mylink ?>"><img src="<?php echo $myImage['thumbUrlPath'] ?>" width="<?php echo
$myImage['thumbWidth'] ?>" height="<?php echo $myImage['thumbHeight'] ?>" alt="" border="0"/></a>



That approach works for working with Nths uploads belonging to Nths records in a list of records. According to Chris
Waddel form Interactive Tools, if you're FOREACHing over your list of records and want to display the Nth upload of each
one, you can use $record['uploadFieldName'][4].

Personally, he likes to assign an upload to a variable (like $upload) so I don't have to repeat the
['uploadFieldName'][4] part, like this:




<?php foreach( $affiliationsRecords as $affiliationsRecord ): ?>
Title: <?php echo htmlencode($affiliationsRecord['title']) ?>

2nd Upload:
<?php $upload = @$affiliationsRecord['uploadFieldName'][4] ?>
<?php if ($upload): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo
$upload['thumbHeight'] ?>" />
<?php else: ?>
None!
<?php endif ?>

<?php endforeach ?>



The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service