PHP randomisation

Associate
Joined
19 Jun 2006
Posts
162
Location
Swansea, Wales
I have a simple website which just basically produces boxes of different content repeatedly in the page.

Eg.

<span id="aBox">Some content 1</span>
<span id="aBox">Some content 2</span>
<span id="aBox">Some content 3</span>

At the moment the page is pure html. I was wondering if anyone could think of a way, perhaps using php, to randomise the layout each time the page is loaded. So one time it would be as above then you hit F5 and it would be...


<span id="aBox">Some content 1</span>
<span id="aBox">Some content 3</span>
<span id="aBox">Some content 2</span>

etc.

Any ideas?
 
Yeh, it's all static. It really is this simplest of things and I didn't want to get into sql with it all.

What you have above seems to work well.

Thanks very much!
 
Is there any way to put a for loop in an array construct?

$files = array ('Some content 1', 'Some content 2', 'Some content 3');

Some content x could eventually go in to the hundreds and i really don't feel like typing out each 'Some content xxx' for each entry.
 
Cheers. I've used your idea but taken it one step further by dynamically creating the 'thelinks.php' file...

Code:
$PATH = $_ENV['DOCUMENT_ROOT'];
	
	$d=$PATH.$dirPath; 
	
	$dir = opendir($d); 
		
	$myFile = "$fileName.txt";
	$fh = fopen($myFile, 'w') or die("can't open file");
	
	while ($f = readdir($dir)) {
		$stringData = $f."\n";
		fwrite($fh, $stringData);
	}
	
	fclose($fh);

The only problem is it puts in '.' and '..' at the start of the file which then means i get two broken links when constructing my links from the array.

Any ideas how to get around this?
 
Back
Top Bottom