Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

include() problem

Status
Not open for further replies.

martinb7

Programmer
Joined
Jan 5, 2003
Messages
235
Location
GB
Hi, i am working on this 2page site that work together, can you tell me whats wrong?

whats happening is that when i use the include(); it places it at the top of the page instead of in the table where i want it.

##code for dotemplate.php##
Code:
<?php 
$main = &quot;testing&quot;;
$logo = &quot;logo&quot;;
$left = include(&quot;navleft.php&quot;);
$right = include(&quot;middlenav.php&quot;);

$pagehtml = implode(&quot;&quot;, file(&quot;template.template&quot;)); // for change layout use &quot;.$_SESSION['template'].'&quot;
           $pagehtml = str_replace(&quot;[## titlebar ##]&quot;, $logo, $pagehtml);
           $pagehtml = str_replace(&quot;[## copyright2 ##]&quot;, $copyright, $pagehtml);
           $pagehtml = str_replace(&quot;[## leftnav ##]&quot;, $left, $pagehtml);
           $pagehtml = str_replace(&quot;[## main ##]&quot;, $main, $pagehtml);
           $pagehtml = str_replace(&quot;[## rightnav ##]&quot;, $right ,$pagehtml);

echo($pagehtml);
?>

##code for template.template##
Code:
<html>

<head>
<meta http-equiv=&quot;Content-Language&quot; content=&quot;en-gb&quot;>
<meta name=&quot;GENERATOR&quot; content=&quot;Microsoft FrontPage 5.0&quot;>
<meta name=&quot;ProgId&quot; content=&quot;FrontPage.Editor.Document&quot;>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=windows-1252&quot;>
<title>New Page 1</title>
</head>

<body>

<table border=&quot;1&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse&quot; bordercolor=&quot;#111111&quot; width=&quot;800&quot; id=&quot;AutoNumber1&quot;>
  <tr>
  <td width=&quot;100%&quot;>[## titlebar ##]</td>
  </tr>
  <tr>
  <td width=&quot;200&quot;>[## leftnav ##]</td>
  <td width=&quot;400&quot;>[## middle ##]</td>
  <td width=&quot;200&quot;>[## rightnav ##]</td>
  </tr>
  <tr>
  <td width=&quot;800&quot;>[## copyright ##]</td>
  </tr>
</table>

</body>

</html>

website url:


im trying to create the same effect as

any ideas?? am i doing it the right way??

thanx


Martin

Computing help and info:

 
its the same, the its called navleft.php!!

try n help me pls!!

wot i get is that it comes up in the top-left instead of in the place wher i want it!

any more ideas??

thanx

Martin

Computing help and info:

 
By now nobody, maybe not even Chacalinc, knows what your code looks like.
Did you make your bav scripts into functions? The fact that the output appears in the wrong place could be:
1. It is still called in the wrong spot.
2. The include statement still produces output.
3. The resulting HTML is invalid and makes the browser display it wrong.

I'd be glad to help, jsut show the current state.
 
ok il put the code there
Code:
#dotemplate.php# - viewed in browser
<?php

im not sure about this bit >>

//include 'navleft.php';

function navleft2(){
	include 'navleft.php';
}

$leftnav = navleft2();

<<

$main = &quot;testing&quot;;
$logo = &quot;logo&quot;;
//$left = include(&quot;navleft.php&quot;);
$right = include(&quot;middlenav.php&quot;);

$pagehtml = implode(&quot;&quot;, file(&quot;template2.template&quot;)); // for change layout use &quot;.$_SESSION['template'].'&quot;
           $pagehtml = str_replace(&quot;[## titlebar ##]&quot;, $leftnav, $pagehtml);
           $pagehtml = str_replace(&quot;[## copyright2 ##]&quot;, $copyright, $pagehtml);
           $pagehtml = str_replace(&quot;[## leftnav ##]&quot;, $leftnav, $pagehtml);
           $pagehtml = str_replace(&quot;[## main ##]&quot;, $main, $pagehtml);
           $pagehtml = str_replace(&quot;[## rightnav ##]&quot;, $right ,$pagehtml);

echo($pagehtml);
?>

#template2.template# - called by dotemplate.php
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>

<body topmargin=&quot;0&quot; leftmargin=&quot;0&quot;>
<table width=&quot;850&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
  <!--DWLayoutTable-->
  <tr> 
    <td height=&quot;100&quot; colspan=&quot;5&quot; valign=&quot;top&quot;><div align=&quot;center&quot;>[## logo ##]</div></td>
  </tr>
  <tr> 
    <td width=&quot;150&quot; rowspan=&quot;2&quot; valign=&quot;top&quot;>[## leftnav ##]</td>
    <td height=&quot;19&quot; colspan=&quot;3&quot; valign=&quot;top&quot;><marquee align=&quot;absmiddle&quot; behavior=&quot;alternate&quot; scrollamount=&quot;5&quot;>
      [## middle nav ##]</marquee></td>
    <td width=&quot;150&quot; rowspan=&quot;2&quot; valign=&quot;top&quot;>[## right ##]</td>
  </tr>
  <tr> 
    <td width=&quot;73&quot; height=&quot;34&quot;> </td>
    <td width=&quot;400&quot; rowspan=&quot;2&quot; valign=&quot;top&quot;><table width=&quot;100%&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
        <!--DWLayoutTable-->
        <tr> 
          <td width=&quot;400&quot; height=&quot;19&quot; valign=&quot;top&quot;><div align=&quot;center&quot;>[## page 
              title ##]</div></td>
        </tr>
        <tr> 
          <td height=&quot;13&quot; valign=&quot;top&quot;><div align=&quot;center&quot;>[## page ##]</div></td>
        </tr>
        <tr> 
          <td height=&quot;21&quot; valign=&quot;top&quot;><div align=&quot;center&quot;>[## created ##]</div></td>
        </tr>
      </table></td>
    <td width=&quot;77&quot;> </td>
  </tr>
  <tr> 
    <td height=&quot;19&quot; valign=&quot;top&quot;><!--DWLayoutEmptyCell--> </td>
    <td> </td>
    <td> </td>
    <td valign=&quot;top&quot;><!--DWLayoutEmptyCell--> </td>
  </tr>
  <tr> 
    <td height=&quot;19&quot; colspan=&quot;5&quot; valign=&quot;top&quot;><div align=&quot;center&quot;>[## copyright 
        ##] </div></td>
  </tr>
  <tr> 
    <td height=&quot;311&quot;> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
</table>
</body>
</html>

#navleft.php# - called by dotemplate.php

<?php function navleft(){
include(&quot;pagecolors.php&quot;);
include(&quot;config.php&quot;);
include(&quot;functions.php&quot;);
?>
<link href=&quot;<?php echo($sitecss); ?>&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot;>
<body topmargin=&quot;0&quot; leftmargin=&quot;0&quot;>
<table width=&quot;200&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; bgcolor=&quot;<?php echo(&quot;$sideColor&quot;); ?>&quot;>
  <!--DWLayoutTable-->
  <tr> 
    <td width=&quot;200&quot; height=&quot;15&quot; valign=&quot;top&quot; bgcolor=&quot;<?php echo(&quot;$barColor&quot;); ?>&quot;><div align=&quot;center&quot;>Main 
        Pages </div></td>
  </tr>
  <tr> 
    <td height=&quot;14&quot; valign=&quot;top&quot; bgcolor=&quot;<?php echo(&quot;$sideColor&quot;); ?>&quot;><div align=&quot;center&quot;><font size=&quot;2&quot;> 
        <?php $query = mysql_query(&quot;SELECT * FROM wrV2pages WHERE section = 'main'&quot;); doWhileLoop($query); ?>
        </font></div></td>
  </tr>
  <tr> 
    <td height=&quot;15&quot;></td>
  </tr>
  <tr> 
    <td height=&quot;18&quot; valign=&quot;top&quot; bgcolor=&quot;<?php echo(&quot;$barColor&quot;); ?>&quot;><div align=&quot;center&quot;>Computing</div></td>
  </tr>
  <tr> 
    <td height=&quot;15&quot; valign=&quot;top&quot; bgcolor=&quot;<?php echo(&quot;$sideColor&quot;); ?>&quot;><div align=&quot;center&quot;><font size=&quot;2&quot;> 
        <?php $query = mysql_query(&quot;SELECT * FROM wrV2pages WHERE section = 'computing'&quot;); doWhileLoop($query); ?>
        </font></div></td>
  </tr>
  <tr> 
    <td height=&quot;13&quot;></td>
  </tr>
  <tr> 
    <td height=&quot;13&quot; valign=&quot;top&quot; bgcolor=&quot;<?php echo(&quot;$barColor&quot;); ?>&quot;><div align=&quot;center&quot;>Community</div></td>
  </tr>
  <tr> 
    <td height=&quot;15&quot; valign=&quot;top&quot; bgcolor=&quot;<?php echo(&quot;$sideColor&quot;); ?>&quot;><div align=&quot;center&quot;><font size=&quot;2&quot;> 
        <?php $query = mysql_query(&quot;SELECT * FROM wrV2pages WHERE section = 'community'&quot;); doWhileLoop($query); ?>
        </font></div></td>
  </tr>
  <tr> 
    <td height=&quot;17&quot;></td>
  </tr>
  <tr> 
    <td height=&quot;10&quot; valign=&quot;top&quot; bgcolor=&quot;<?php echo(&quot;$barColor&quot;); ?>&quot;><div align=&quot;center&quot;>Other</div></td>
  </tr>
  <tr> 
    <td height=&quot;14&quot; valign=&quot;top&quot; bgcolor=&quot;<?php echo(&quot;$sideColor&quot;); ?>&quot;><div align=&quot;center&quot;><font size=&quot;2&quot;> 
        <?php $query = mysql_query(&quot;SELECT * FROM wrV2pages WHERE section = 'other'&quot;); doWhileLoop($query); ?>
        </font></div></td>
  </tr>
</table>
</body>
<?php } ?>

hope this helps!

pls try n fix the prob!

thanx


Martin

Computing help and info:

 
There are several things that I see right away.
1. The most important is that HTML documents are only allowed to contain a single <body> tag. Each of your sub-documents seems to contain a full <body> tag. That will certainly create invalid HTML.

2. Your code
Code:
function navleft2(){
    include 'navleft.php';
}

$leftnav = navleft2();
defeats itself. When you call the navleft2() function the HTML will be put into the output stream. That's why it always appears first.

You need to:
a) get rid of the extraneous <body> tags or extract the content between <body> .... </body>
b) not call the function anwhere else than where the output should go or rewrite it in such a way that the output goes into a string.

I think you are mixing up the reading the contents of a file into a string variable with inclusion using include(). The file reading wouldn't help you either as you have also PHP code in the files that needs to be executed, there are further dependencies.

Make a simple schematic overview of what you want the modules to do. It will help you get a clearer picture of what's happening.
 
Martin,

In navleft.php you did not put the page on a variable, that's why it is showed instead to put it on $left_nav var. Take a look to my previous post, where all the page (navleft) is in $out variable.

2nd place, as DRJ478 states, you must have *only one* <body> tag. Tags <link ..> for css put it inside <head> tag.

cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top