shuffle images

4 posts by 2 authors in: Forums > CMS Builder
Last Post: November 21, 2012   (RSS)

Re: [SkidderChains] shuffle images

By gregThomas - November 19, 2012

Hi SkidderChains,

I've come up with something that should do what you want:

// load records from 'gallery_2'
list($gallery, $gallery_2MetaData) = getRecords(array(
'tableName' => 'gallery_2',
'orderBy' => 'RAND()',
'loadUploads' => true,
'allowSearch' => false,
));

//shuffle all of the images for each record
foreach($gallery as $images){
shuffle($images['image']);
}

//counter
$n = 0;
//max number of images you want to pull from each section;
$max = 5;
while($n <= $max): ?>

<?php foreach($gallery as $key => $images): ?>

<?php //If there is a picture in the image array with a key of $n, assign it to the $image varible, else return false
if($image = @$images['image'][$n]): ?>

<img src="<?php echo $image['urlPath']; ?>" alt="<?php echo $image['info1']; ?>" />
<?php endif; ?>

<?php endforeach; ?>
<?php $n++; ?>
<?php endwhile; ?>


This is just an example, and you will have to modify the code to work with your setup.

So I'm using the getRecords function to randomly sort the sections, then cycling through them and displaying each individual image using the $n variable to select a single image from the image array. So first it will display all of the images from each section with a key of 0, then 1, 2 etc.

Let me know if this isn't what your after.

Cheers
Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] shuffle images

By SkidderChains - November 21, 2012

It seems to be working, but taking a long time to load the images and is effecting the transition.... Any thoughts. I will have to trouble shoot on this end.

Thanks for the help....

Re: [SkidderChains] shuffle images

By gregThomas - November 21, 2012

I've just had a look at the site and the images seemed to be loading quickly for me, could it have been your connection or hosting service being temporarily slow? If your still having the issue there are a few things you could try:

You could try lowering the quality of the images to the point where the quality isn't affected, but the image file size is reduced.

Check the images you are uploading aren't any larger than they need to be, as larger images take longer to load. Looking at the example you've given it looks as if you'r already doing this.

Finally, check that the image slider your using preloads the images, I think the image slider your using already does do this.
Greg Thomas







PHP Programmer - interactivetools.com