Random Information

e85andyou

New Member
Messages
49
Reaction score
0
Points
0
I have been working with a friend on his site and I have run into a road block. He has a site with 3 columns. We have been trying to find a way to display a page at random in the third column using server side includes. We have 3 different pages that we want to randomize on page load. If anyone knows of a way or has seen anything on the net we would appreciate the help.
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
I have been working with a friend on his site and I have run into a road block. He has a site with 3 columns. We have been trying to find a way to display a page at random in the third column using server side includes. We have 3 different pages that we want to randomize on page load. If anyone knows of a way or has seen anything on the net we would appreciate the help.

If you're using php, I can probably help.

All you need is a random number generator (say 1-3) and assign it to a variable. ($randomnumber)

Then add this random number to an include string.

e.g. $var_include_path='http://yoursite/includes/file".$randomnumber.".php'

Then save 3 independant include files with the content you want to display in the main page and number them accordingly.

In the main page in your 3rd <td>, you can then use the random number to select one of the 3 pages via the include statement within that cell.

You could use as many different pages as you wanted with this.

Let me know if you need further clarification.
 

quantum1

New Member
Messages
68
Reaction score
0
Points
0
Expanding on freecrm's idea, you could have a text file or db table with a list of files to show. You can read the list into an array, then pick a random number between 1 and the number of files, inclusive. This way you can add to the list of files at will by adding to the text file or db table. If you wanted to randomly show a file from a certain directory you could do a directory listing into an array and use the same idea.
 

scopey

New Member
Messages
62
Reaction score
0
Points
0
PHP:
<?php
$num = rand(1,3);
switch($num){
case 1:
$include = "file1.php";
break;
case 2:
$include = "file2.php";
break;
case 3:
$include = "file3.php";
break;
}
include "inludepath/".$include;
?>

And here's an idea similar to Quantum's.

PHP:
$files = array("directory/file1.php","directory/file2.php","directory/file3.php");
include $files[rand(0, (sizeof($files) -1))];
 
Last edited:

freecrm

New Member
Messages
629
Reaction score
0
Points
0
I've PM'd back to your friend.

Scopey - that's made life easier - thanks!!
Edit:
Thanks Scopey that is exactly what we were looking for. It works great.

Arrrgghh - there's goes my street cred!! :biggrin:

Glad it worked for you.
 
Last edited:
Top