• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

php switch help...

<|R0cKm@nX|>

New Member
i got no idea why this dont work...can anybody teach me please?
PHP:
<?

switch($_REQUEST['id']){

    case '1':
    echo "111";
    break;

    default:
    echo "default";
    break;
}

?>

it keeps on showing default when i enter page.php?id=1
 
I understand what you are trying to do.
A few ideas that will make it easier
PHP:
<?
// these are part of the array $page[]
$page[0] = 'pages/default.txt';
$page[1] = 'pages/home.txt';
$page[2] = 'pages/email.txt';
$page[3] = 'pages/links.txt';
//Check if id is empty
if(!empty($_GET['id'])) $id = $_GET['id'];
else $content = $page[0];
// get the appropriate page
$content = $page[$id];
//include page
include($content);
?>
That is one way of doing it.
Then you could make it simpler where you dont have to add to $page[] :
PHP:
//path to the directory where the pages are
$path = 'path/to/file/';
// check to see if id is set
if(!empty($_GET['id'])) $id = $_GET['id'];
else $content = 'path/to/default.txt';
//create the path including the appropriate page
$content = $path . $id . '.txt';
// include page
include($content);

the first example would us:
www.page.com/index.php?id=1
the second would use:
www.page.com/index.php?id=page
 
Originally posted by <|R0cKm@nX|>
i got no idea why this dont work...can anybody teach me please?
Your code is correct but before PHP 4.1.0, $_REQUEST is not defined .
So if you use earlier versions that problem happens .
 
Back
Top