Jump to content

PHP include affecting other results on page


howardmoore

Recommended Posts

Hi,

 

I am building a site using PHP includes to show a set bit of content on lots of pages (i.e. some standard repeating text).

 

The problem is that when I call the include, all the data shown below where it appears is the same as the include, and not the main page that I am trying to call. Both the include and the page on which is sits need to call a field from a MySQL database called 'content'.

 

Can anyone think of a workaround for this?

 

Many thanks,

Neil

So you have an include that calls "contents" and another one that calls "contents"

 

ie

Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello 
<?php
include "databasecontents.php";
?>

Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello

contents, contents, contents, contents, contents, contents, contents,

 

WORLD WORLD WORLD WORLD WORLD WORLD WORLD WORLD WORLD WORLD WORLD 
<?php
include "databasecontents.php";
?>

WORLD WORLD WORLD WORLD WORLD WORLD WORLD WORLD WORLD WORLD WORLD

contents, contents, contents, contents, contents, contents, contents,

 

so when you do this

Main Main Main Main Main Main 
<?php
include "page1.php";
include "page2.php";
?>

 

and you end up with

Main Main Main Main Main Main

Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello

contents, contents, contents, contents, contents, contents, contents,

WORLD WORLD WORLD WORLD WORLD WORLD WORLD WORLD WORLD WORLD WORLD

contents, contents, contents, contents, contents, contents, contents,

 

if the above is the problem then you have a few solutions

#1 use include_once("databasecontents.php")

#2 break it up more

ie

Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello 
<?php
include "databasecontents.php";
?>

 

Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello Hello 

<?php
include "page1.html";
include "databasecontents.php";
?>

 

then in main call include "page1.html"; instead of include "page1.php";

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.