...

View Full Version : problem in INCLUDE a FILE



eshban
09-12-2005, 07:04 AM
I want to include a file 'one.php' in my project. But in file 'one.php' one more file 'b.php' in already included which is actually the header. I just want one.php file to be included in my project not 'b.php' file. What can i do

kindly help me in this regard.

webby
09-12-2005, 08:20 AM
If b.php is already included in one.php and you want to include one.php into another file, then b.php will automatically get included along with it no matter what. That's like gluing two pictures together and then trying to display them separately in a collage.

You can include each file individually where you want both files to be included, so you can include the other one separately in other files.

Alternatively, you can assign the code that is currently in b.php to a variable, then echo that variable wherever you want b.php to occur, although it won't be b.php anymore and you can completely get rid of that file, as the code will be in one.php.

For example, right now you might have something like this in one.php:

<?
// some code here
include("b.php");
?>
But instead, you could do something like this in one.php:

<?
// some code here
$whatever = "whatever you currently have in p.php here";
?>
And then in the pages where you want to include the extra code:

<?
include("one.php");
echo($whatever);
?>
And where you don't want to include the extra code:

<?
include("one.php");
?>

Or if you keep them in separate files, one.php and p.php:


<?
include("one.php");
include("p.php");
?>
It also depends on where p.php is currently included in your one.php file, as those examples only work as described if p.php is included at the end of one.php with no other code after it. It would be easier to determine the best method if we had more information.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum