showing wrong number of thumbs

5 posts by 2 authors in: Forums > CMS Builder
Last Post: March 31, 2010   (RSS)

By rez - March 30, 2010 - edited: March 30, 2010

Why is this code showing 16 thumbs? I want to display a certain number of random thumbs.



<?php foreach ($galleryRecords as $record): ?>
<?PHP shuffle($record['uploads']) ?>
<?php $counter = 1; ?>
<?php foreach ($record['uploads'] as $upload): ?>

<li><a href="<?php echo $upload['urlPath'] ?>" ><img src="<?php echo $upload['thumbUrlPath'] ?>" /></a></li>

<?php if($counter == 8) : ?><?PHP break ?><?php endif; ?>
<?php $counter++ ?>
<?php endforeach ?>
<?php endforeach ?>

Re: [rez] showing wrong number of thumbs

By Chris - March 30, 2010

Hi rez,

"break" only exits out of one loop, so your code will display a random selection of (up to) 8 uploads from each of your records in $galleryRecords.

Did you want to display a random selection of 8 uploads from all your records?
All the best,
Chris

Re: [chris] showing wrong number of thumbs

By rez - March 30, 2010 - edited: March 30, 2010

Oh. That could come in handy, cool.

But yes, I wanted to show random thumbs from all the records. Actually 12.

Re: [chris] showing wrong number of thumbs

By rez - March 31, 2010

Very useful for a lot of random things. :)