Help with a Hyperlink

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
silent_assassin
Forum Newbie
Posts: 8
Joined: Mon Mar 20, 2006 5:47 pm

Help with a Hyperlink

Post by silent_assassin »

I have the following code used

Code: Select all

<?PHP 

switch ($_GET[page]){ 

     case "home":
       include 'index.php';
     
	break;     

     case "console": 
          include 'console.php'; 
     
     } 
?>
and a hyperlink of

Code: Select all

<a href="index.php?page=console">Click Here to Get to the Console</a>
When I click the link it takes me to console.php but then it also shows the contents on index.php below the contents of console.php.

What am I doing wrong


P.S. It still does it when i remove the include index.php line out
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

is that the entire contents of that page?

switch($_GET[page]) should be switch($_GET['page']) .. but I'm not sure that matters.. i dunno
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Code: Select all

switch($_GET['page'])
{
	case 'home':
		include 'index.php';
		break;     

	case 'console':
		include 'console.php';
		break;

	default:
		include 'index.php';
}
Try this for starters. Then check if any includes, are including other files in your switch statement. Where is the switch by the way? In all files, or just a few?
silent_assassin
Forum Newbie
Posts: 8
Joined: Mon Mar 20, 2006 5:47 pm

Post by silent_assassin »

nah that don't matter it still does it even if its 'page' or page
silent_assassin
Forum Newbie
Posts: 8
Joined: Mon Mar 20, 2006 5:47 pm

Post by silent_assassin »

the switch is in the index.php file...the console.php as sweet fa in apart from 1 line of text just to test it.

When i put the

Code: Select all

default: 
        include 'index.php';
in then it just screws up and the index page don't load at all
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

index would only be a default in pages other than index.php - in fact index.php probably shouldn't even have the index.php case full stop - double inclusions?

You go to index.php?page=home. You are now at index.php, with the switch re-including the same page???

You should try placing all page includes into a separate directory, then using index.php simply as a single point of entry. Then have a switch statement in index.php which contains include 'home.php' rather than index.php, with th default set to home.php.

Might work that way.
silent_assassin
Forum Newbie
Posts: 8
Joined: Mon Mar 20, 2006 5:47 pm

Post by silent_assassin »

I am not trying to go to index.php?page=home i am trying to access index.php?page=home, so I am trying to load another page called console.php But it still appears with the contents of index.php below it.
eyespark
Forum Commoner
Posts: 50
Joined: Tue Jan 24, 2006 7:36 am

Post by eyespark »

Code: Select all

if (isset($_GET['page']) && $_GET['page']) == "console"){
include 'console.php';
} else {your index page}
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Have a look over at our Useful Posts Thread
Post Reply