Member Avatar for 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!

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

Recommended Answers

All 5 Replies

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 for diafol

How about just:

$num = rand(1,3);
include "page$num.php";
commented: Thanks for the code! +5
Member Avatar for 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 for 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 for LastMitch

@pritaeas
@diafol

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

commented: To Rectify what some retard did to LastMitch +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.