Need help with switches and links

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Gimpy
Forum Commoner
Posts: 42
Joined: Tue Jun 14, 2005 1:12 am
Location: Fort Worth, TX, US
Contact:

Need help with switches and links

Post by Gimpy »

Alright, Im trying to relearn php as it has been about a year or two since I actually used it and im a lil rusty with making links with switches on the page. I have heard rumors that the php5.x.x has broke the simplification of this. If this is true what is the best practice? saving links in arrays or variables? Could use some insight?'

Here is what Im messing with so far -

Code: Select all

<div style="text-align:center">Home | <a href="<? =$_SERVER['PHP_SELF']; ?>?nav=time">Project 1</a>|
		<a href="<? =$_SERVER['PHP_SELF']; ?>?nav=p2"> Project 2</a> | Project 3 | Project 4
and here is the switch:

Code: Select all

switch ($nav) {
case "time":
//include '/projects/timeclock/index.php';
header('Location: /projects/timeclock/index.php');
break;
case "p2":
echo "i equals 1";
break;
case "p3":
echo "i equals 2";
break;
case "p4":
echo "i equals 2";
break;
default:
include 'home.php';
}
Thanks,
Gimpy
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Need help with switches and links

Post by requinix »

Looks like it will work fine as long as you set the value of $nav:

Code: Select all

$nav = (empty($_GET["nav"]) ? "" : (string)$_GET["nav"]);
Post Reply