Re: Re: Customise Index page using PHP????

From: Date: Fri, 12 Jul 2002 04:08:32 +0000
Subject: Re: Re: Customise Index page using PHP????
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-107311@lists.php.net to get a copy of this message
I'd say there's an easier way than switches... <? if(!empty($_GET['page_id'] && is_int($_GET['page_id'])) { $page_id = $_GET['page_id']; } else { // default if no id was passed, or it wasn't an integer $page_id = "1"; } $file = "inc/page_" . $page_id . ".inc"; // eg page_18.inc if(file_exists($file)) { include($file); } else { include('inc/page_missing.inc'); } ?> The difference being that there's no extra code (case statements) for 1000 different page_id's, or just 5 page_id's, and I've included pretty much all the fallbacks for missing page_id, missing include files, etc etc. You just need a /inc/ dir full of page_n.inc files. Good luck! Justin French on 12/07/02 12:43 AM, Martin Clifford (MLC1@nrc.gov) wrote: > The easiest way to accomplish that is by using switches. Here is an example: > > switch($pageid) { > default: > include("default_page.inc"); > break; > case "18": > include("page_18.inc"); > break; > } > > With that in your index.php page, it will look for the variable $pageid, and > depending on what it is set to, display the appropriate information. In this > instance, it will display the default index page by default (if $pageid is > empty), or page_18.inc if $pageid = 18. > > Hope that helps :o) > >>>> "Craig" <craig@sitedesign.net> 07/11/02 10:42AM >>> > I want to acheive something like this > > http://www.claviga.com/index.php?pageid=18 > >

« previous php.general (#107311) next »