Hi,

I'm having some problems trying to create a template.

I have a file in a folder called index.php.

That file calls two other files. One from the same folder called local.php (which contains some variables like "$a = 'firetruck').

The other is from another folder (on the same server) that is called display.php and does all the display and mysql searching.

What I try to do (so far, unsuccessfully) is say, in the file display.php, SELECT from table where whatever = $a. ($a being set in the local.php file).

Unfortunately, this just isn't working. Are variables included from one file not available to includes from another folder? Am I missing something simple?

I know I can do it with a include display.php?a=firetruck, but I'm looking for something slightly easier, if it exists.

    Works here:

    <?php
    
    include 'inc1.php';
    
    include 'foobar/inc2.php';
    
    ?>
    
    <?
    
    //inc1.php
    
    $foo="Bar!";
    
    ?>
    
    <?
    
    //foobar/inc2.php
    
    echo $foo;
    
    ?>

    Expected result. Anything else unusual about your setup?

      8 days later

      Actually it was my mistake. I was including files like this:

      "http://www.mywebsite.com/incl.php"

      rather than say

      include "../../incl.php"

      Because I was bringing them in via "http" instead of within php, the variables were not being passed. As soon as I flipped it around to ../ the whole thing worked.

        Originally posted by idiparker
        Because I was bringing them in via "http" instead of within php, the variables were not being passed. As soon as I flipped it around to ../ the whole thing worked.

        It helps to remember the difference between a file path and a URL 🙂

          Write a Reply...