Member Avatar
LastMitch

Hi

I'm trying to learn how to create a random page using rand() function but also using the $num to switch each page.

Is there a way to click a button? I only used the Refresh Button on Firefox. Plus it's not really display the data but only page name which is page1.php, page2.php, page3.php.

Each page has one word in which is

page1.php = How 
page2.php = are  
page3.php = you?


<?php
$num = rand(1,3);

switch ($num) {
 case 1: echo "page1.php";
 break;
 case 2: echo "page2.php";
 break;
 case 3: echo "page3.php";
 break;
}

?>

I appreciate any Suggestions or explaining to why it doesn't display the word but instead it display the file name "page1.php" Thanks!

commented: To Rectify what some retard did to LastMitch +0

echo just display what you type into it. If you want to execute the page, use include:

case 1: include 'page1.php'; break;
commented: Thanks for the code and explanation! +5
Member Avatar
diafol

How about just:

$num = rand(1,3);
include "page$num.php";
commented: Thanks for the code! +5
Member Avatar
LastMitch

@pritaeas

Thanks for the reply and explanation!

I will test out the code. Thanks!

commented: To Rectify what some retard did to LastMitch +0
Member Avatar
LastMitch

@diafol

Thanks for the reply and code.

I will also test it out. Thanks!

commented: To Rectify what some retard did to LastMitch +0
Member Avatar
LastMitch

@pritaeas
@diafol

Both options works! I appreciate both of your help! Thanks!

commented: To Rectify what some retard did to LastMitch +0