Forum Moderators: coopster

Message Too Old, No Replies

displaying pages in pages with php

can i do this automatically?

         

jungle brother

3:00 pm on Apr 24, 2003 (gmt 0)

10+ Year Member



i think this is the right section, sorry if its not.

im new to php, and i've found a tutorial on some website i cant remember that tells you how to do the whole

<?
switch ($_GET['action'])
{
case 'news'
include('news.htm');
break;
default: include('welcome.htm');
break;
}
?>

thing, and this works fine with my site. the problem is, i've got hundreds of pages i want to include, and i'm adding more all the time, i dont want to have to keep adding another "case 'asdf' include('asdf.htm')" for every page.

what i really want, is for the php page to automatically include the html file with the same name as the variable in the URL, so for example if the url was

calendar.php?month=may2003

then the php page would automatically try and load may2003.htm in the same folder. (it would be better if it could load "/calendar/may2003.htm" but im not that worried if thats too complicated.

sorry if i havent explained it very well, i'm still a n00b hehe :)

mavherick

3:29 pm on Apr 24, 2003 (gmt 0)

10+ Year Member



You could use this code instead of your switch statement:

// Define the path to your file
$pathToFile = "/dir/to/my/file/";

$fileToInclude = $pathToFile.$_GET['action'].".htm";

if(is_file($fileToInclude))
{
include($fileToInclude);
} else {
// file doesn't exist, include default
include($pathToFile."welcome.htm");
}

Now for your calendar.php, you'd do something similar, but replace $_GET['action'] by $_GET['month']

hope that helps

mavherick

[added]just noticed the default case[/added]

jungle brother

4:39 pm on Apr 24, 2003 (gmt 0)

10+ Year Member



ahh thankyou so much, youve just saved my life hehe