Tutorial Related Links
If you wish to view a full list of all the tutorials that have been posted by Tony Bob Design
or wish to browse our arhives, click on the links above.
Categories
If you wish to browse our tutorials by category, navigate with the links above.
Tutorials - PHP - PHP Navigation
Posted by:Tony Bob on Sep 14 2006
The main code
Step 1
Code
<?phpswitch ($HTTP_GET_VARS[id]) {
//Default - case
default:
include "news/news.php";
break;
//Fonts - case
case 'resources=fonts':
include 'resources/fonts.php';
break;
//Scripts - case
case 'resources=scripts':
include 'resources/scripts.php';
break;
}
?>
Break the code down
Step 2
Code
<?phpswitch ($HTTP_GET_VARS[id]) {
First off <?php is required to notify that you want php coding to start.
Second of all $HTTP_GET_VARS [id] is telling the document to get the variable "id" you can change "id" to what ever you want. But what ever you change it to must be changed after index.php? So for instanced what we have above, would make the address look like this http://blahblah.com/index.php?id
Code
//Default - casedefault:
include "main.php";
break;
Now you are defining the default document that is to be loaded if no ?id is specified. So type in include" "; your default doc such as a news page. Make sure you have break; on its own line, and make sure that it is in there after each case.
Code
//Fonts - casecase 'fonts':
include 'fonts.php';
break;
Next what we have is a case it is basically the same thing as the default case but you are defining what to do if the web address is blahblha.com/index.php?id=fonts . What it is saying is if "Fonts" is existant after ?id= then include 'fonts.php'; so what you want to do is replace fonts.php and change the case to what ever you want.
Code
}?>
Insert code to display content
Step 3
Put the entire php code where you want each page to load, keep in mind that each page will load at the same place no matter what, and backgrounds are not included either.
Link up your navigation
Step 4
The final step is to link text or buttons or what ever to each switch.. You do this by adding an <a href="index.php?id=fonts">Some Text</a> to your site or navigation.
Now when ever someone clicks that link "Some Text" it will goto the case "fonts" look to see what action it is told to do.. since it is include the page fonts.php it will include fonts.php where ever you place the php code at.
Continue to link each ahref to each case changing the id name (?id=fonts) make sure you do not specify a target or it will popup in a new window.
Note: Make sure to save the page that has the php code in it as a .php or .php3 file, if you don't it will not work and your navigation code will go kabloome.
Rate This Tutorial
Comments
Add A comment










