PDA
Partners

View Full Version : Random content order?


I, Brian
September 18th, 2005, 05:42 PM
Sorry to ask a simple question, but I'm looking to randomise a display of content, which are called up with basic PHP include files.

So if there are 5 images, I'm calling them up as:



<!-- site content above -->
<?PHP include("/home/user/public_html/section1.php"); ?>
<?PHP include("/home/user/public_html/section2.php"); ?>
<?PHP include("/home/user/public_html/section3.php"); ?>
<?PHP include("/home/user/public_html/section4.php"); ?>
<?PHP include("/home/user/public_html/section5.php"); ?>
<!-- footer below -->




How would I randomise with a script within the body itself?

Many thanks for any replies.

Marshall
September 19th, 2005, 01:21 AM
Something like this might work

<!-- site content above -->
<?php

$selection = mt_rand(1,5);
if($selection == "1"){
include("/home/user/public_html/section1.php");
}elseif($selection == "2"){
include("/home/user/public_html/section2.php");
}elseif($selection == "3"){
include("/home/user/public_html/section3.php");
}elseif($selection == "4"){
include("/home/user/public_html/section4.php");
}else{
include("/home/user/public_html/section5.php");
}

?>
<!-- footer below -->