View Full Version : php switch help...
<|R0cKm@nX|>
January 26th, 2003, 03:48
i got no idea why this dont work...can anybody teach me please?
<?
switch($_REQUEST['id']){
case '1':
echo "111";
break;
default:
echo "default";
break;
}
?>
it keeps on showing default when i enter page.php?id=1
spec
January 26th, 2003, 13:30
I understand what you are trying to do.
A few ideas that will make it easier
<?
// 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[] :
//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
Salam
January 26th, 2003, 18:24
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 .
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.