weird stuff with include statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mdawg414@gmail.com

    weird stuff with include statement

    Hey guys, please bear with me cause I am a major newbie at php. I am
    building a website and have it so that the content in the middle of the
    page changes but the banner on top and the panels on the sides do not.
    The way I am doing this is by having a top.php file and a bottom.php
    file and in my file index.php it would look like this:
    <?php
    include("top.ph p");
    ?>
    Here is my index stuff...
    <?php
    include("bottom .php");
    ?>

    and that works great. However, I thought it would be cool to have it so
    that one of the panels changed for each website so that it was specific
    to the page you were on but the others stayed the same. So I thought I
    could do include("top.ph p?panel=homepag e"); and edit the top.php page
    accordingly. However, this does not work. Thanks so much for your help.

    Matt

  • Andy Hassall

    #2
    Re: weird stuff with include statement

    On 1 Jul 2005 14:36:02 -0700, mdawg414@gmail. com wrote:
    [color=blue]
    >Hey guys, please bear with me cause I am a major newbie at php. I am
    >building a website and have it so that the content in the middle of the
    >page changes but the banner on top and the panels on the sides do not.
    >The way I am doing this is by having a top.php file and a bottom.php
    >file and in my file index.php it would look like this:
    ><?php
    >include("top.p hp");
    >?>
    >Here is my index stuff...
    ><?php
    >include("botto m.php");
    >?>
    >
    >and that works great. However, I thought it would be cool to have it so
    >that one of the panels changed for each website so that it was specific
    >to the page you were on but the others stayed the same. So I thought I
    >could do include("top.ph p?panel=homepag e"); and edit the top.php page
    >accordingly. However, this does not work. Thanks so much for your help.[/color]

    ?panel=homepage is for HTTP requests.

    This include() is not doing an HTTP request, it is reading from the
    filesystem.

    There's no such file named "top.php?panel= homepage". So it won't work.

    Since this is PHP reading PHP, you simply set the appropriate variable in your
    outer file, and the file in the inner scope have it available as described in
    the manual.



    --
    Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

    Comment

    • Thomas Kaarud

      #3
      Re: weird stuff with include statement

      * Andy Hassall wrote:
      [color=blue]
      > On 1 Jul 2005 14:36:02 -0700, mdawg414@gmail. com wrote:
      >[color=green]
      >> Hey guys, please bear with me cause I am a major newbie at php. I am
      >> building a website and have it so that the content in the middle of the
      >> page changes but the banner on top and the panels on the sides do not.
      >> The way I am doing this is by having a top.php file and a bottom.php
      >> file and in my file index.php it would look like this:
      >> <?php
      >> include("top.ph p");
      >> ?>
      >> Here is my index stuff...
      >> <?php
      >> include("bottom .php");
      >> ?>
      >>
      >> and that works great. However, I thought it would be cool to have it so
      >> that one of the panels changed for each website so that it was specific
      >> to the page you were on but the others stayed the same. So I thought I
      >> could do include("top.ph p?panel=homepag e"); and edit the top.php page
      >> accordingly. However, this does not work. Thanks so much for your help.[/color]
      >
      > ?panel=homepage is for HTTP requests.
      >
      > This include() is not doing an HTTP request, it is reading from the
      > filesystem.[/color]

      Correct!

      But what he really want to know is how to make it work in real life, not
      only the technical reason it doesn't.

      Matt, what you will have to do is to have some function to call for in the
      top.php and bottom.php if you want to have some kind of dynamic content.

      What you could do is something like this:

      <?php
      //this is top.php
      function write_1()
      {
      echo 'This is 1';
      }
      ?>

      <?php
      //this is bottom.php
      function write_2()
      {
      echo 'This is 2';
      }
      ?>


      <?php
      //This is mainfile, e.g. index.php
      include("top.ph p");
      write_1();
      ?>
      Here is my index stuff...
      <?php
      include("bottom .php");
      write_2();
      ?>


      --

      Thomas

      Comment

      • Jerry Stuckle

        #4
        Re: weird stuff with include statement

        Thomas Kaarud wrote:[color=blue]
        > * Andy Hassall wrote:
        >[color=green]
        >> On 1 Jul 2005 14:36:02 -0700, mdawg414@gmail. com wrote:
        >>[color=darkred]
        >>> Hey guys, please bear with me cause I am a major newbie at php. I am
        >>> building a website and have it so that the content in the middle of the
        >>> page changes but the banner on top and the panels on the sides do not.
        >>> The way I am doing this is by having a top.php file and a bottom.php
        >>> file and in my file index.php it would look like this:
        >>> <?php
        >>> include("top.ph p");
        >>> ?>
        >>> Here is my index stuff...
        >>> <?php
        >>> include("bottom .php");
        >>> ?>
        >>>
        >>> and that works great. However, I thought it would be cool to have it so
        >>> that one of the panels changed for each website so that it was specific
        >>> to the page you were on but the others stayed the same. So I thought I
        >>> could do include("top.ph p?panel=homepag e"); and edit the top.php page
        >>> accordingly. However, this does not work. Thanks so much for your help.[/color]
        >>
        >>
        >> ?panel=homepage is for HTTP requests.
        >>
        >> This include() is not doing an HTTP request, it is reading from the
        >> filesystem.[/color]
        >
        >
        > Correct!
        >
        > But what he really want to know is how to make it work in real life,
        > not only the technical reason it doesn't.
        >
        > Matt, what you will have to do is to have some function to call for in
        > the top.php and bottom.php if you want to have some kind of dynamic
        > content.
        >
        > What you could do is something like this:
        >
        > <?php
        > //this is top.php
        > function write_1()
        > {
        > echo 'This is 1';
        > }
        > ?>
        >
        > <?php
        > //this is bottom.php
        > function write_2()
        > {
        > echo 'This is 2';
        > }
        > ?>
        >
        >
        > <?php
        > //This is mainfile, e.g. index.php
        > include("top.ph p");
        > write_1();
        > ?>
        > Here is my index stuff...
        > <?php
        > include("bottom .php");
        > write_2();
        > ?>
        >
        >[/color]
        Why go to all that trouble?

        Just put

        <?php
        echo "This is 1";
        ?>

        in top.php and include it where you want it (instead of calling a function).

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • Thomas Kaarud

          #5
          Re: weird stuff with include statement

          * Jerry Stuckle wrote:
          [color=blue]
          > Thomas Kaarud wrote:[color=green]
          >> <?php
          >> //this is top.php
          >> function write_1()
          >> {
          >> echo 'This is 1';
          >> }
          >> ?>
          >> <?php
          >> //this is bottom.php
          >> function write_2()
          >> {
          >> echo 'This is 2';
          >> }
          >> ?>
          >> <?php
          >> //This is mainfile, e.g. index.php
          >> include("top.ph p");
          >> write_1();
          >> ?>
          >> Here is my index stuff...
          >> <?php
          >> include("bottom .php");
          >> write_2();
          >> ?>
          >>[/color]
          > Why go to all that trouble?
          >
          > Just put
          >
          > <?php
          > echo "This is 1";
          > ?>
          >
          > in top.php and include it where you want it (instead of calling a
          > function).
          >[/color]

          Ofcourse, but it seems like this being a person who want to know how to
          use included files, and obviously you don't have a singe included file for
          any kind of include you would like....

          --
          Thomas

          Comment

          • mdawg414@gmail.com

            #6
            Re: weird stuff with include statement

            Thanks for your help guys. Worked perfectly.

            Comment

            Working...