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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.