Forum Moderators: coopster
*****Code:*********************************
<?php
if(isset($_GET['page']))
{
switch($_GET['page'])
{
case "home":
?>HOME HTML HERE<?php
break;
case "test":
?>TEST HTML HERE<?php
break;
case "help":
?>HELP HTML HERE<?php
break;
default:
?>DEFAULT HTML HERE<?php
}
}
?>
*****************************************
Everything works right except on the default page when you add the html there and you got the the page it works but when you go to like index.php?page=help it has the html for that page plus the default page.
What do I do to make them like separate pages but all in one file.
To show specific content when no variable is appended to the URL you can use an IF, which says IF condition 1 is met do something, otherwise dont.
I use this on one of my sites I have a page called artist.php. If this is called without a variable, I show a list of all artists. If a variable is on the URL (artist.php?a=1) I show only relevant information for that artist.
<?php
function viewPageSection($page)
{
switch($page) {
case 'home':
$section = 'home';
break;
case 'test':
$section = 'test';
break;
case 'help':
$section = 'help';
break;
default:
$section = false;
break;
}
return $section;
}//get the page name from the get request
if(!empty($_GET['page']))
$section = viewPageSection($_GET['page']);
//page information goes below add whatever content you like
if (isset($section) && $section == 'home') {
//home section info goes here
print "<p>Print out some home section text.</p>";
} elseif (isset($section) && $section == 'test') {
//test section info goes here
print "<p>Print out some test section text.</p>";
} elseif (isset($section) && $section == 'help') {
//help section info goes here
print "<p>Print out the help information section.</p>";
} else {
//if all above fail then display this
print "<p>Just Information that gets shown if all other page checks fail.</p>";
}
?>
Best Regards,
Brandon