Jump to content

Help with some menu navigation code


tsluss

Recommended Posts

I'm working on a website for my boss and I'm a novice at PHP at the moment, however I felt this was within my grasp.  I am running into some issues though and was hoping another set of eyes my have some recommendations for me.

 

First of all I'm building the website in all <div> and formated with CSS.  What I'm shooting for is the standard left hand side bar navigation menu which a user clicks on and once the button is clicked I want the body <div> to reload with an included file.  This doesn't need to be elaborate, it's a small site, so a simple setup is fine for this.

 

I have tried several variations on this site, but basically what I was trying to do was use $_GET to get the variable value once the link was clicked and then use a switch statement to determine what file is to be displayed. 

 

Here is an example of what I have so far:

 

Code for one of the buttons:

 

<div class="button_top">

<a href="index.php?location=home">

<img alt="Home" class="button" name="btn1" src="images/home_up.gif"

onmouseover"home_over()" onmouseout="home_normal()" onmousedown="home_down()" alt="Home" /></a>

</div>

 

Code for the body <div> where the switch statement is:

 

<?php

switch ($_GET['location'])

    {

case 'home': include ("home.php"); break;

case 'services': include ("services.php"); break;

default: include ("home.php"); break;

    }

?>

 

There will of course be more than this once I'm finished, but I'm trying to get these two working properly before I go on.  I have also tried having a small snippet of code at the begining of the file to assign the variable $location a value and set my switch on it but if it was empty to default the include to home.php and still had no luck.

 

If anyone has any input I would greatly appreciate it.

Link to comment
https://forums.phpfreaks.com/topic/38251-help-with-some-menu-navigation-code/
Share on other sites

the code looks fine to me, are you trying to change the page within a certain div on youe page or the hole page all together? if yes then wha tyou need is javascript.

if not and your getting ablank page try this:

 

<?php  
$location = $_GET['location'];                
switch ($location){
   case "home":   
   include "home.php"; 
   break;
   case "services": 
   include "services.php";   
   break;
   default:      
   include "home.php";   
   break;            
   }
?>

OK, well I've identified the source of the problem and as it turns out it looks like I've been spinning my wheels.  I've been running PHP Triad on my computer to do the coding and testing locally versus uploading it to a server.  After reading the reply here and seeing that my code was good, I uploaded it and it works just fine on the server.  Novice mistake I suppose.  Thanks for the help!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.