Random Placement from Single Editor

3 posts by 3 authors in: Forums > CMS Builder
Last Post: August 18, 2011   (RSS)

I've created a single Editor specifically for a 'photo bank' for the client. Originally I had it as a multi editor, but the client would have to upload the images one at a time... the single editor is much easier to upload since the can upload several.

I know how to get the header code to display records randomly with the multi section editor.. but not for the single.

here's my viewer code:
list($interior_page_photosRecords, $interior_page_photosMetaData) = getRecords(array(
'tableName' => 'interior_page_photos',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$interior_page_photosRecord = @$interior_page_photosRecords[0]; // get first record


and here's the body code:
<?php foreach ($interior_page_photosRecord['photos'] as $upload): ?>
<p><img src="<?php echo $upload['thumbUrlPath'] ?>" class="image-border" /></p>
<p><?php echo $upload['info1'] ?></p>
<?php break; ?>
<?php endforeach ?>


I inserted the break to display only one image at a time.. just need to insert the random action
John Tedesco

Creative Director



JAM Graphics

Re: [jtedescojam] Random Placement from Single Editor

By Dave - March 31, 2010

Hi jtedescojam,

How many uploads will there be? If there will be hundreds you may want to use a different method as it will use a lot of server resources to load them all each time just to display one.

But try this (untested) code:

<?php shuffle($interior_page_photosRecord['photos']); ?>
<?php foreach ($interior_page_photosRecord['photos'] as $upload): ?>
<p><img src="<?php echo $upload['thumbUrlPath'] ?>" class="image-border" /></p>
<p><?php echo $upload['info1'] ?></p>
<?php break; ?>
<?php endforeach ?>



The PHP shuffle() function randomizes an array. See: http://php.net/shuffle

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com