I am working on my simpleslideshow snippet to make it better. now its also posible to place the snippet more then once on a page, But now I like to ad random into the snippet
I tryed some things like randomize de count but that way it does not use all the files. so what my question is if there is a way to or read out a folder in random order or mix up the array somehow so that all the files are in the array but in random order?
here is how far I am now:
<?php
$path = "assets/images/$folder/";
if(!isset($name)) $name="slides";
if(!isset($folder)) return; // no folder? quit.
$interval = isset($interval) ? $interval : 5;
$slides = array();
if ($dh = @opendir($path)) {
while(($file = readdir($dh)) !== false) {
if ( !preg_match('/\.thumb*/',$file) && preg_match('@.png$|.gif$|.jpg$@', $file) && $file != '.' && $file != '..' ) {
$slides[] = $path.$file;
}
}
}
$num = count($slides);
$rand= mt_rand (1 , $num-1);
$last = $num-1;
if(isset($js)){$script ="";}else{$script = '<script type="text/javascript" src="assets/js/slides.js"></script>';}
$script .= '<img id="'.$name.'" src="'.$slides[$rand].' " alt="" width="'.$width.'" height="'.$height.'"/>';
$script .= '<script type="text/javascript">';
$script .= 'setTimeout("RunSlideShow(\"'.$name.'\",\"';
for($i=$rand;$i<$num-1;$i++) {
$script .= $slides[$i] . ';';
}
$script .= $slides[$rand] . '\",';
$script .= $interval . ')",5000);';
$script .= '</script>';
unset ($rand);
return $script;
?>
this looks ok (well a bit) I get a random list of images somehow but never all the images that are counted, because I use $rand here: for($i=$rand;$i<$num-1;$i++) { but when I set this to 1 then its not random any more.
I also tried to do this: $script .= $slides[$rand] . ’;’; but that way I get 20 times the same image except for the last 3 or so.
the best way would be an option to randomize the $slides array that way it will always be random I think and you never get the same images in one slide show.
I tried my friend Google but could not find an answer I understood, so if anyone could help me with this that would be great.
Dimmy