TeamPhotoshop
Reviews, updates and in depth guides to your favourite mobile games - AppGamer.com
Forum Home Latest Posts Search Help Subscribe

Sections on a PHP page

Page: 1 Reply
Jul 8th 2004#155158 Report
Member since: Jul 8th 2004
Posts: 1
I've got a index.php page, basically its a HTML page converted to PHP as I had to, to allow the news section to work.

My site is set up so that there is a header logo, a section with links to the left of the page, a section of links to the right of the page and a center section where my news appears.

What I'm looking to do is to keep all of the page in the same, links, logo etc, but have the news section change upon clicking a link.

Say for instance,

I go to my page http://myeducationalphppage/

then have read the news on the index page so I want to look at the e.g. Maths section, but I dont want to have to copy and paste the whole php source code for every link that I make.

I want the e.g. Maths section to appear where the news was on the index page..

I think I read up about it a while back, but I have no idea what its called or how to do it so I couldn't search..

Sorry if there is already a thread for this.

Regards
Reply with Quote Reply
Jul 8th 2004#155163 Report
Member since: Nov 26th 2001
Posts: 2586
include (), include_once (), require (), require_once () .... Those are the functions you are looking for, if I read you correctly.

The difference between them:

include () -- this will include that section of code , and if there is some fubar in your code, or you need it included in another place it's possible to include it again.

include_once () -- this is the same as above, except if that section of code is already included, then it won't do it again.

require () -- same as include ,except if you can't include it, you will get a big fat error message and no page output. For instance if you have some database connection variables in a seperate file, you can say to require those functions on pages that need them.

require_once () -- same as above, except included only 1 x's ...


You can include anything. Does not have to be a php page. For instance you can include a footer html page: include "footer.html";

These are not "real" functions so you don't need open and close parenths.

All you are doing is "cutting" the code out of your php page and putting it into a seperate file, then putting an include where that code was.

So for what you want this might be appropriate:

[php]

include_once "header.php";

include_once "left_nav.html";

/* page outout here.... */

include_once "right_nav.html";

include_once "footer.html";

?>
[/php]

Then the only thing that will change page to page is the page content. Makes updating your site real easy.
Reply with Quote Reply
Page: 1 Back to top
Please login or register above to post in this forum