Jump to content

multiple include


OLM3CA

Recommended Posts

hi;
My code is :

              [code] if($page=='SubmitNew') { include ('submit.php'); }

if ($page=='Contact') { include ('contact.php'); }

if ($page=='faq') { include ('faq.php'); }

if ($page=='cat' && $category=='1') {
$cat="shopping";
$m="14";
include ('outer.php');
}

              else { include('inner.php'); }[/code]


My question is when I open the index.php, I see inner.php ,Its ok.
But when I click on the link
[code]?page=cat&category=1
?page=faq , ?page=Contact [/code] I see the page  [color=red]inner.php [/color] is still included to my page.
In example:
When I click on ?page=Contact  I see the contact.php and below  inner.php
I dont want that inner.php shown again.
Link to comment
https://forums.phpfreaks.com/topic/20717-multiple-include/
Share on other sites

Rather using seperate if statements use and if/eseif/else statement.
[code]<?php

if($page == 'SubmitNew')
{
    include 'submit.php';
}
elseif($page=='Contact')
{
    include 'contact.php';
}
elseif($page == 'faq')
{
    include 'faq.php';
}
elseif($page == 'cat')
{
    if($category == '1')
    {
        $cat = "shopping";
    $m = "14";

        include 'outer.php';
    }
    else
    {
        include 'inner.php';
    }
}

?>[/code]

Or better option would be a switch/case statement:
[code]<?php
switch($page)
{
    case 'SubmitNew':
        include 'submit.php';
    break;

    case 'Contact':
        include 'contact.php';
    break;

    case 'faq':
        include 'faq.php';
    break;

    case 'cat':

        if($category == '1')
        {
            $cat = "shopping";
        $m = "14";

            include 'outer.php';
        }
        else
        {
            include 'inner.php';
        }

    break;
}
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/20717-multiple-include/#findComment-91657
Share on other sites

Here's another sample... might help

[code]
<?php
switch ($page) {
case 'submit' :
$content = 'submit.php';
break;

case 'contact' :
$content = 'contact.php';
break;

case 'faq' :
$content = 'faq.php';
break;

default :
$content = 'submit.php';
}
?>

<head></head>
<title></title>
<body

<table>
<tr>
<td>
<?php require_once 'header.php'; ?>
</td>
</tr>
<tr>
<td>
<?php require_once $content; ?>
</td>
</tr>
<tr>
<td>
<?php require_once 'footer.php'; ?>
</td>
</tr>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/20717-multiple-include/#findComment-91667
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.