Hey, just wanted t share a cool little function I once came upon a while back when I was new to PHP. The name itself is pretty self explanatory allowing for you to easily switch through pages, so lets start.
Start off with a base code like this:
Now let me explain what this does, first of all we initiate the switch function then use the $_GET statement to grab the page we want to view.PHP Code:<?php
switch($_GET[page]) {
default:
echo "<a href='?page=hello'>Hello</a>";
break;
case 'hello':
echo "Hello";
break;
}
?>
default: is basically the default page upon page load, so if you went to www.site.com/index.php you'd get a link with "Hello" on it. We then use the break; statement to break the page.
Case.
We use the case statement to grab the end of the url from the default echo which in our case was hello, this allows us to link to an entirely different page using that simple feature.
Have fun!
Oh, you can also do multiple clauses by using:
See what I did?PHP Code:<?php
switch($_GET[page]) {
default:
echo "<a href='?page=hi'>Hi</a>";
break;
case 'hi':
echo "<a href='?page=bonjour'>Bonjour</a>";
break;
case 'bonjour':
echo "Bonjour!";
break;
}
?>
Closed by Invent (Forum Moderator): Thread closed due to prevent (further) arguments.










lol.