Do something like below:
PHP Code:
<?php # Random method. // Start the sessions session_start();
// Give each picture a number. $picture[1] = "http://www.example.com/picture1.png"; $picture[2] = "http://www.example.com/picture2.png"; $picture[3] = "http://www.example.com/picture3.png";
// Let set some variables. $maxnumber = count($picture); // Count how many there are in the array,
// Pick a random number between these: $random_number = rand (1,$maxnumber); // This will pick a number between 1 and 3.
// Now lets check it was not the last picture used: if($random_number == $_SESSION['lastrandomnumber']){ // It's the same as the last number. if($random_number == $maxnumber){ // if it's the 4. $random_number = $random_number - 1; } else { // otherwise show the nest one. $random_number = $random_number + 1; } }
// Then show that picture echo $picture[$random_number];
// Now lets update the session: $_SESSION['lastrandomnumber'] = $random_number;
?>
Of course, this is a simplified version. Using the session thing you could probably store what has been already scene. You would also need to take out the randomness
On the other hand, you could use this:
PHP Code:
<?php # Add one method. // Start the sessions session_start();
// Give each picture a number. $picture[1] = "http://www.example.com/picture1.png"; $picture[2] = "http://www.example.com/picture2.png"; $picture[3] = "http://www.example.com/picture3.png";
// Let set some variables. $maxnumber = count($picture); // Count how many there are in the array, $next_picture = $_SESSION['lastrandomnumber'] + 1; // what the next picture is.
// Pick a random number between these: if($next_picture == $maxnumber){ $next_picture = 0; // Back to beginning. }
// Then show that picture echo $picture[$next_picture];
// Now lets update the session: $_SESSION['lastrandomnumber'] = $next_picture;
?>
Again, this method is not perfect (they will always start from 0).
__________________
My Blog/Site: Please login or register to view this content. Registration is FREE
Last edited by rogem002; 05-18-2008 at 11:44 AM..
|