Gazan Posted March 16, 2009 Share Posted March 16, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/149714-solved-using-switch-to-show-different-pages-doesnt-work/ Share on other sites More sharing options...
Maq Posted March 16, 2009 Share Posted March 16, 2009 That is how you do it. What exactly happens? Have you echoed $page to see what's actually in it? Should it be $page=$_GET['show']; ? Simple tutorial Quote Link to comment https://forums.phpfreaks.com/topic/149714-solved-using-switch-to-show-different-pages-doesnt-work/#findComment-786156 Share on other sites More sharing options...
Gazan Posted March 16, 2009 Author Share Posted March 16, 2009 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.. Quote Link to comment https://forums.phpfreaks.com/topic/149714-solved-using-switch-to-show-different-pages-doesnt-work/#findComment-786158 Share on other sites More sharing options...
Maq Posted March 16, 2009 Share Posted March 16, 2009 $page = isset($_GET['page']) ? $_GET['page'] : "default"; Quote Link to comment https://forums.phpfreaks.com/topic/149714-solved-using-switch-to-show-different-pages-doesnt-work/#findComment-786161 Share on other sites More sharing options...
Gazan Posted March 16, 2009 Author Share Posted March 16, 2009 Thanks alot! Solved the problem Quote Link to comment https://forums.phpfreaks.com/topic/149714-solved-using-switch-to-show-different-pages-doesnt-work/#findComment-786164 Share on other sites More sharing options...
Maq Posted March 16, 2009 Share Posted March 16, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/149714-solved-using-switch-to-show-different-pages-doesnt-work/#findComment-786171 Share on other sites More sharing options...
Gazan Posted March 16, 2009 Author Share Posted March 16, 2009 Yeah, i see that now.. I'd love to but, somehow i don't have access to do so.. :s Quote Link to comment https://forums.phpfreaks.com/topic/149714-solved-using-switch-to-show-different-pages-doesnt-work/#findComment-786174 Share on other sites More sharing options...
Maq Posted March 16, 2009 Share Posted March 16, 2009 It's the tab called [sOLVED] in the bottom right. Quote Link to comment https://forums.phpfreaks.com/topic/149714-solved-using-switch-to-show-different-pages-doesnt-work/#findComment-786178 Share on other sites More sharing options...
Gazan Posted March 16, 2009 Author Share Posted March 16, 2009 It's not there, together with the others.. Quote Link to comment https://forums.phpfreaks.com/topic/149714-solved-using-switch-to-show-different-pages-doesnt-work/#findComment-786187 Share on other sites More sharing options...
Maq Posted March 16, 2009 Share Posted March 16, 2009 It's not there, together with the others.. K, nvm don't worry about it. Quote Link to comment https://forums.phpfreaks.com/topic/149714-solved-using-switch-to-show-different-pages-doesnt-work/#findComment-786189 Share on other sites More sharing options...
Gazan Posted March 16, 2009 Author Share Posted March 16, 2009 Alright. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/149714-solved-using-switch-to-show-different-pages-doesnt-work/#findComment-786192 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.