Jump to content

Archived

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

OLM3CA

multiple include

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.

Share this post


Link to post
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]

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.