PHP Dynamic Pages with INCLUDE tag

What I want happen is for introduction.php and mainContent.php to load link’s respective pages within them when clicked. If I was to click a link from mainMenu.php, I want to load that inside of introduction.php. When links from subMenu.php is clicked, I want to load them inside of mainContent.php. But here’s the problem!

When I click the link in mainMenu.php, the link’s page load inside of introduction.php and mainContent.php instead of being in introduction.php alone. I want one link to load in introduction.php when I click a link from mainMenu.php, and if I click a link in subMenu, I want that link to open up a page in mainContent.php.

What happens is when I click one or the other link from either mainMenu.php or subMenu.php, I reset the other link…

How can I go about this the proper way?

index.php:

<?php
include('header.php');
include('mainMenu.php');
include('introduction.php');
include('subMenu.php');
include('mainContent.php');
include('navigation.php');
include('footer.php');
?>

mainMenu.php:

<!-- mainMenu.php -->
<nav>
    <ul>
        <li><a href="index.php">Home</a></li>
        <li><a href="index.php?page=whysave.php">Why Save</a></li>
        <li><a href="index.php?page=testimonials.php">Testimonials</a></li>
        <li><a href="index.php?page=contactus.php">Contact Us</a></li>
    </ul>
</nav>
<!-- end of mainMenu.php -->

subMenu.php:

<!-- subMenu.php -->
<nav>
    <ul>
        <li><a href="index.php?page=programs.php">Programs</a></li>
        <li><a href="index.php?page=savewithadp.php">Pay Less with ADP</a></li>
        <li><a href="index.php?page=savingguide.php">Saving Guide</a></li>
        <li><a href="index.php?page=affiliate.php">Become an Affiliate</a> <span>Call Us</span></li>
    </ul>
</nav>
<!-- end of subMenu.php -->

introduction.php:

<!-- introduction.php -->
<div>
    <!-- video message -->
    <div>
    <?php
        if (isset($_GET['page'])) {
            $page = $_GET['page']; /* gets the variable $page */
        }
        if (!empty($page)) {
            include($page);
        }
    ?>
    </div>
    <!-- contact form -->
    <div></div>
</div>
<!-- end of introduction.php -->

mainContent.php:

<!-- mainContent.php -->
<div>
    <?php
        if (isset($_GET['page'])) {
            $sub_page = $_GET['page']; /* gets the variable $page */
        }
        if (!empty($sub_page)) {
            include($sub_page);
        }
    ?>
</div>
<!-- end of mainContent.php -->

This whole set up seems rather odd to me but here’s a solution to the issue at hand. Your submenu would need a change to have something like
?subpage=whatever

instead of
?page=whatever

then your mainContent.php will look at $_GET[‘subpage’]

You see, both introduction.php and mainContect.php are doing the same thing. And you’re including them both one right after the other. You’re going to include $_GET[‘page’] twice.

That’s true. I tried what you mentioned, but the issue is when I click on one of the links from either section, the previous link’s page disappears from the other section. Now I’m looking for a way to save the last link clicked so 2 section can be displayed at the same time…