PHP Switch


Befor u start using this tutorial you need to deside what GET variable your navigation will use. For example, this tutorial will use $_GET['page'], this means that our links will be displayed as href='?page=about'>About


PHP Code
  1. <?php
  2.  
  3. switch($_GET['page']) { //gets the case and you can edit 'page' to be what you like. example: ?page= or ?sitename=
  4.  
  5. case "about": // this is the case that the switch would display when clicked
  6. include ('about.php'); //when the case is called it will display what page you have added. also u can add an echo instead of a include
  7. break; //stops the case i believe
  8.  
  9. case "hello"://this is the case that the switch would display when clicked
  10. echo "Hello world!";// this is display whatever text you add again u can change is to a include
  11. break; //stops the case i believe
  12.  
  13.  
  14. default: // default would be whatever page u want to be displayed befor someone clicks a link i use news.php
  15. include ('news.php'); // page thats displayed befor a link is clicked or if someone tryed to access a page that isnt there.
  16. break; //stops the case i believe
  17.  
  18. }
Adam981's Avatar
Author:
Views:
2,569
Rating:
Posted on Saturday 7th June 2008 at 04:05 PM
darklight19
darklight19's Avatar
I've been doing it this way for a while. :)
Posted on Friday 6th June 2008 at 06:56 PM
Adam981
Adam981's Avatar
Thanks, not bad for my first tutorial :P
Posted on Friday 6th June 2008 at 11:48 AM
ilyas-shezad
ilyas-shezad's Avatar
Nice very simple and easy to understand
Posted on Friday 6th June 2008 at 06:48 AM
SkillMaster
SkillMaster's Avatar
I use this in a lot of my tutorials.
Posted on Friday 6th June 2008 at 03:43 AM
Adam981
Adam981's Avatar
Thanks :) i figured i'd post a working one :P
Posted on Friday 6th June 2008 at 03:40 AM
Nathan
Nathan's Avatar
this is a great tutorial and its easy to use.