Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2005
    Location
    Lahore, Pakistan
    Posts
    150
    Thanks
    2
    Thanked 0 Times in 0 Posts

    problem in INCLUDE a FILE

    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.

  • #2
    New Coder
    Join Date
    Aug 2005
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:
    PHP Code:
    <?
    // some code here
    include("b.php");
    ?>
    But instead, you could do something like this in one.php:
    PHP Code:
    <?
    // 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:
    PHP Code:
    <?
    include("one.php");
    echo(
    $whatever);
    ?>
    And where you don't want to include the extra code:
    PHP Code:
    <?
    include("one.php");
    ?>
    Or if you keep them in separate files, one.php and p.php:

    PHP Code:
    <?
    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.
    Last edited by webby; 09-12-2005 at 09:22 AM. Reason: Forgot a semicolon :p


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •