Jump to content


Photo

multiple include


  • Please log in to reply
3 replies to this topic

#1 OLM3CA

OLM3CA
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts
  • LocationCyprus

Posted 14 September 2006 - 11:19 AM

hi;
My code is :

             
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');	}


My question is when I open the index.php, I see inner.php ,Its ok.
But when I click on the link
?page=cat&category=1
?page=faq , ?page=Contact
I see the page  inner.php 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.
AMD rather than Intel , PHP rahter than ASP

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 14 September 2006 - 11:35 AM

Rather using seperate if statements use and if/eseif/else statement.
<?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';
    }
}

?>

Or better option would be a switch/case statement:
<?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;
}
?>


#3 laide234

laide234
  • Members
  • PipPipPip
  • Advanced Member
  • 33 posts

Posted 14 September 2006 - 12:07 PM

Here's another sample... might help

<?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>


#4 OLM3CA

OLM3CA
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts
  • LocationCyprus

Posted 14 September 2006 - 12:20 PM

Thank you very much wildteen88 It works ;)
AMD rather than Intel , PHP rahter than ASP




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users