You are here: Re: weird stuff with include statement « PHP Programming Language « IT news, forums, messages
Re: weird stuff with include statement

Posted by Jerry Stuckle on 07/02/05 05:07

Thomas Kaarud wrote:
> * Andy Hassall wrote:
>
>> On 1 Jul 2005 14:36:02 -0700, mdawg414@gmail.com wrote:
>>
>>> 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.php");
>>> ?>
>>> 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.php?panel=homepage"); and edit the top.php page
>>> accordingly. However, this does not work. Thanks so much for your help.
>>
>>
>> ?panel=homepage is for HTTP requests.
>>
>> This include() is not doing an HTTP request, it is reading from the
>> filesystem.
>
>
> 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.php");
> write_1();
> ?>
> Here is my index stuff...
> <?php
> include("bottom.php");
> write_2();
> ?>
>
>
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@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация