Multiple Page on a single page using PHP with Switch Condition
We will use GET Variable for checking the condition, which page we have to show.
Following is the code:
<?php
// make condition
if(isset($_GET['page']))
{
$pagetoshow = $_GET['page'];
} else {
$pagetoshow = "index";
}
// make condition
// execute condition
switch($pagetoshow)
{
case "about":
// content for about
echo "This is the about page.";
// content for about
break;
case "contact":
// content for contact
echo "This is the contact page.";
// content for contact
break;
default:
// content for index
echo "This is the index page.";
// content for index
break;
}
// execute condition
?>
Following will be the O/P of the code:
Save page as index.php
- index.php
This is the index page.
- index.php?page=about
This is the about page.
- index.php?page=contact
- index.php?page=index
This is the index page.
Other then then the above value, If value of page is passes different.
Then Default condition will be executed, which is the index page.
Comments
Post a Comment