link system in php
Link System in PHP - Tutorial
by - Titan (Rob)


First, we have to setup a basic navigation bar.


<div style='float:left; width:40%;'>
<a href='page1.php'> Link To Page 1</a><br>
<a href='page1.php'> Link To Page 1</a><br>
<a rhef='page1.php'> Link To Page 1</a><br>

There, we got our basic navigation. And no it is not a typo, i meant for all three of those links to be the same.

This is where things are gonna start getting tricky cause now we gotta start adding the PHP stuff.

Now, we gotta add lil pieces to the end of the url's in order for our PHP Link System to work.


<a href='page1.php?id=1'> Link Area 1 on Page 1</a><br>
<a href='page1.php?id=2'> Link Area 2 on Page 1</a><br>
<a rhef='page1.php?id=3'> Link Area 3 on Page 1</a><br>

What this will do, is that when you click on a link, it will set the variable id = to the number that is there. That number is what desides on what information is displayed.

Now we have to add our information, this is the msot complicated part.


switch ($_GET['id'])
case 1:
echo "This Is Area 1!";

case 2:
echo "This Is Area 2!";

case 3:
echo "This Is Area 3!";

echo "Please Click On A Link!"

Now, lemme explain some of this. the $_GET['id'] takes any information in a url after a ? . So, what this is doing is getting the value of the variable id which we defined for each of our links before. Each of the cases in the Switch is equal to one of the values that we have defined on the end of our links. the 'default' is what is displayed when the page is first loaded and no one has clicked on a link.

To add more to each case, add an echo "code here" ; for each line you are adding AND MAKE SURE YOU DO NOT DELETE THE " break; "

And That's It. Download example file

/ End Tutorial

PS: Tutorial written with the permission of the Author!
by - Titan (Rob)