Identify first upload in multiple upload field

3 posts by 2 authors in: Forums > CMS Builder
Last Post: February 9, 2009   (RSS)

By bruno - February 9, 2009

I was wondering if there was a way to identify each image in a multiple upload image field. I'm trying to isolate the link to the first upload. The code I currently have links to each image within the foreach loop.
Heres my viewer code

<?php

require_once "/Documents/design/Brunello-Redesign/dev/cmsAdmin/lib/viewer_functions.php";

list($print_portfolioRecords, $print_portfolioMetaData) = getRecords(array(
'tableName' => 'print_portfolio',
));



and my foreach loop for the images:

<?php foreach ($record['main_image'] as $upload): ?>


<a href="<?php echo $upload['urlPath'] ?><img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" />


<?php endforeach ?>

Re: [bruno] Identify first upload in multiple upload field

By Dave - February 9, 2009

Hi Bruno,

There's a few ways to do that. You can use break; to stop after just one loop:

<?php foreach ($record['main_image'] as $upload): ?>
... show image ...
<?php break; ?>
<?php endforeach ?>


Or you can load just the first image like this:

<?php $upload = @$record['main_image'][0]; ?>
<?php if ($upload): ?>
... show image ...
<?php endif ?>


You can add brackets and a number on the end to select an image from the list (starting the count from zero).

Hope that helps!
Dave Edis - Senior Developer

interactivetools.com