Nargis
Nargis

Reputation: 25

A PHP command to open a php page inside an index.php file

I have an index.php file. Inside the index.php file I am using the following php code to open a "home.php" page from a "pages" folder:

<?
switch (isset($do)) {
    case $do=='home':
        include("pages/home.php");
        break;
}?>

It works fine. My problem is that I want to open a "about.php" page inside the index.php as well. The "about.php" page is not inside the "pages" folder but rather in a different folder called "about". I am using this php code but it is not working:

<?
switch (isset($show)) {
case $show=='about':
    include("about/about.php");
    break;
}?>

Can someone please point where I am wrong? I appreciate your help.

Upvotes: 0

Views: 154

Answers (1)

Martin Heraleck&#253;
Martin Heraleck&#253;

Reputation: 5779

Your switch syntax is incorrect. Try this:

if (isset($_GET['show']))
{
    switch ($_GET['$show'])
    {
        case 'home':
            include 'pages/home.php';
            break;

        case 'about':
            include 'about/about.php';
            break;
    }
}

And then use URLs like website.com/index.php?show=home or website.com/index.php?show=about.

Your first code works but most likely by a mistake. isset($do) in switch probably returns false because $do doesn't exist. $do=='home' statement returns also false so the code in first case is executed.

Upvotes: 1

Related Questions