First I have to explain a bit of how this works. We use what’s called a URL query string, You have probably scene something like this “index.php?name=test” Were it says name is referring to the case statement. In any other example, if u were to put hello $name and use the URL file.php?name=James then the output would be “hello James”?.
So in this case name will be the case you wish to communicate with and the page you wish to view is tutorials thus we use index.php?name=tutorials, in my case I use 2 one for content and one for sub-nav. To do this we use the & character to indicate that there is a second variable or case statement that we can’t to communicate with.
For our mission her we will only use one case statement.
We have home.php, page1.php, page2.php, and style.css. You can grab them here. Nothing special in here, but let’s have a look at the code for our little site.
<?php
switch( $_GET['name'] )
{
case "page1": // page 1
include("page1.php");
break;
case "page2": // page 2
include("page2.php");
break;
default: // default page
include("home.php");
break;
}
?>
In the above code we see that we use the switch () function to change between our pages. The variable name can be anything you want as long as you remember to change your URL. If name doesn’t have a value then php will loop thro until it hits the default portion of the code. In this case we want it to be home.php so when you access your site with site.php you won’t get a error and you will receive the default content. If you want to see page 1 then we would use site.php?name=page1 and so on.
As you can see the site is nothing special, we have a table with the php code in it, cut and paste the above code into notepad and save it as site.php and put it with the in the zip. Upload it to your web server and test it out. You may be asking your self well great what good is this really. Well as you can see we have one page (site.php) and out content is in their own , every time you update your website you probably spend a lot of time editing your old code, this way when you update your design you have 1 file to change, and your content is all safe and already formatted. It will greatly speed up your productivity.
It’s the second best thing to a data base driven website. So have a look at the finished product.