Jump to content

[SOLVED] Using switch to show different pages doesn't work


Recommended Posts

Hey experts, i'm having this issue with switch..

 

It's just that, i use it to show different pages. Etc. www.url.com?show=gallerypage, www.url.com?show=contactpage. I want to show some content by default, if none of the above options are chosen. My code are as follow:

 

$page = $_GET['page'];

switch ($page) {

case 'contactpage':
echo "This is the contact page.";
break;

case 'gallerypage':
echo "This is the gallery page':
break;

default:
echo "This is the frontpage.";
break;

}

 

with this i want to make it like, if there has not been chosen a $page then it shows the default "This is the frontpage." But how do i make it work like that?

Yeah, thats what i'd like. Like, the links in the menu will be as i've typed with www.url.com/index.php?show=example. But when i go onto the page (www.url.com/index.php) it shall show some content as default, and then when you click some of the menu links, it will go to one of the switch options with the matching value.

 

EDIT:

 

I get the following error "no index defined" with the script..

Thanks alot! Solved the problem :)

 

YW, it was because $_GET['page'] wasn't even set so there was no value to even give $page and the switch didn't know what to do and threw an exception.

 

Please mark as solved.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.