3

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!

Votes + Comments
To Rectify what some retard did to LastMitch
3
Contributors
5
Replies
7
Views
5 Years
Discussion Span
Last Post by LastMitch
1

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

case 1: include 'page1.php'; break;
Votes + Comments
Thanks for the code and explanation!
1

How about just:

$num = rand(1,3);
include "page$num.php";
Votes + Comments
Thanks for the code!
3

@pritaeas

Thanks for the reply and explanation!

I will test out the code. Thanks!

Votes + Comments
To Rectify what some retard did to LastMitch
3

@diafol

Thanks for the reply and code.

I will also test it out. Thanks!

Votes + Comments
To Rectify what some retard did to LastMitch
3

@pritaeas
@diafol

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

Votes + Comments
To Rectify what some retard did to LastMitch
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.