Php navigation

software development

#1

Something is wrong with this code, and I cant decipher exactly what.

I’ve got a template page called index.php.

index.php contents:

<?php switch($page) { case 'bio': @ require_once ("inc/bio.php"); break; case 'work': @ require_once ("inc/work.php"); break; case 'words': @ require_once ("inc/words.php"); break; case 'photos': @ require_once ("inc/photos.php"); break; case 'contact': @ require_once ("inc/contact.php"); break; default: require ("inc/bio.php"); } ?>

then i have a bunch of include php pages, in the proper places.

The links do nothing but when i load the page it defaults to the required bio.php page.

What can I do to get these links to work?

Thanks in advance.


#2

If I am reading that right you are missing the $page=$_SERVER[’$_GET’]; Before the switch.
Silk


#3

[quote]The links do nothing but when i load the page it defaults to the required bio.php page.

What can I do to get these links to work?[/quote]
Your links are creating a querystring like this:

?id=bio

Therefore, you will need to change your switch statement to read the querystring. Also, I recommend that you use the DOCUMENT_ROOT environment variable to make your code a little more portable. It means the includes will work in any subdirectory, without having to change the path:

<?php switch($_GET['id']) { case 'bio': @ require_once ($_SERVER['DOCUMENT_ROOT']."/inc/bio.php"); break; case 'work': @ require_once ($_SERVER['DOCUMENT_ROOT']."/inc/work.php"); break; case 'words': @ require_once ($_SERVER['DOCUMENT_ROOT']."/inc/words.php"); break; case 'photos': @ require_once ($_SERVER['DOCUMENT_ROOT']."/inc/photos.php"); break; case 'contact': @ require_once ($_SERVER['DOCUMENT_ROOT']."/inc/contact.php"); break; default: require ($_SERVER['DOCUMENT_ROOT']."/inc/bio.php"); } ?>--------
Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]