Hello
Currently i'm using this PHP code to create random images in fixed DIVS.
I have 7 jpgs that i randomly want to load in a <div>. My client doesn't want to have PHP so i'm thinking JS.
Is there anybody out there who wants to help me. I can find a lot of JS load random files. But the tricky thing is that the JS is not allowed to duplicate. So he can use each JPG once.
Code:<?php // rotate images randomly but w/o dups on same page - format: // <img src='rotate.php?i=0'> - rotate image #0 - use 'i=1' // for second, etc // (c) 2004 David Pankhurst - use freely, but please leave in my credit $images=array( // list of files to rotate - add as needed "IMAGES/1.jpg", "IMAGES/2.jpg", "IMAGES/3.jpg", "IMAGES/4.jpg", "IMAGES/5.jpg", "IMAGES/6.jpg", "IMAGES/7.jpg" ); $total=count($images); $secondsFixed=1; // seconds to keep list the same $seedValue=(int)(time()/$secondsFixed); srand($seedValue); for ($i=0;$i<$total;++$i) // shuffle list 'randomly' { $r=rand(0,$total-1); $temp =$images[$i]; $images[$i]=$images[$r]; $images[$r]=$temp; } $index=(int)($_GET['i']); // image index passed in $i=$index%$total; // make sure index always in bounds $file=$images[$i]; header("Location: $file"); // and pass file reference back ?>


Reply With Quote

Bookmarks