Using PHP Include to create static Header & Menu sections, but load Content Section

X

X10

Guest
Hello all,
I was hoping someone here could help me identify issues I'm having using the include statement and loading of pages.

Here is the basic version of the code & files that I have:

index.php:

<html><head>
<title>My Main Page
</title></head>
<body>
<table>
<?php include "header.php";?>
<table>
<tr>
<td bgcolor="#FF3311" width="20%">Navigation

<?php include "nav.php"; ?>
</td>
<td width="80%"> Content of page goes here:
<?php if($action != null) { include "$action.php"; } else { include "indexcontent.html"; }?>
</td>
</tr>
</table>
</body></html>

nav.php

<a href="index.php?action=test1">
opens test1.php page
</a>

<a href="index.php?action=test2">
opens test2.php page
</a>

with lots of links like that

header.php

<tr>
<td>
image.gif

</td>
</tr>

indexcontent.html and test1/2.php can be assumed to have any old rubbish in them, lets say they just contain text for now.

With my code, which is, granted, much longer than this example, but syntactically the same, the header will stay no matter what you do, it will not reload, but whenever you click a link in the nav it reloads the nav section and loads the page into the content section.
What I want it to do is just load the content in the content part of the page and keep the Header & Nav static.
NOTE: What is interesting, just putting this code in as is onto the site, *appears* to work as desired. So I don't know why my code seems to reload the Nav section.
If anyone could help me I would really appreciate it.

X10
 
W

wyrd_fish

Guest
if you don't want to reload the nav section, it HAS to be in a differnt frame, you can not just refresh part of a page.

PHP is a server side scripting language, this means that the script is run on the server and sent to the browser, so teh whole page needs refreshing to see the new page...

i did somthing similar on my IT coursework, exept I used a database.

http://mooses.34sp.com/mncc

PS if your planning of running scripts in the included pages, make shure that PHP is set up corectaly on the server to allow this.
 
W

wyrd_fish

Guest
PPS the header does reload, you just don't notice it

PPPS link???
 
L

LazyJim

Guest
frames

what about the support for frames and iframes?
Which browsers allow frames, which allow iframes?

Don't forget if you have a frameset to include a noframes section which which is each page made of header, nav and content that all reloads each time.
 
W

wyrd_fish

Guest
most/all newish browsers support frames, i think, bu IFrames are IE only...
 
W

wyrd_fish

Guest
PS you would then need al the content twice (with a no frames content) why not just not use frames as they are crapy
 
X

X10

Guest
Many thanks for the replies guys, finally I can understand this all.
Right, so umm, would you guys actually use Frames, every web developer I talk to says "Frames are Evil" or "Frames are more Evil than Tables" or "Frames are teh L0s3" (sorry about that last one ;)

I've heard interesting things about Layers, hmm I just checked and they're not commonplace.

What would you guys say.

The reason I ask all this is that I'd like to optimise the pages as much as possible, from a Server and Client perspective. So the smaller I can make each page (a la via Include's) that's good for me and file management, and if I can set it so that people only download the content they need, that would save download time for them.

Anyway, many thanks for your time.

X10
 
W

wyrd_fish

Guest
my itcw used code simmilar to this...

Code:
<?PHP

if($page != "home" or $page != "stuff" or $page != "junk" or !$page){
    $page = "home";
}

if($page == "home"){
    // Stuff for home page
    print("");
}elseif($page == "stuff"){
    // Stuff for home page
    print("");
}elseif($page == "junk"){
    // Stuff for home page
    print("");
}else{
    //error message
    print("");
}

?>

hope this helps.... insteasd of coments put in some database stuff, and there you have one of the best ways of doing stuff, as its easy to change without FTP ing a new file up there...

http://mooses.34sp.com/blue/admin (this link will only give you a PW prompt)

yopu too could have an admin page for changing / adding data...
 
S

(Shovel)

Guest
IE supports <iframe>, and Mozilla (Gecko) certainly did last time I checked.

However, while IE will let you size an iframe by % (e.g width=100%), Mozilla did not.

I don't use these any more, so I can't say whether Mozilla/Firebird supports % width now, though % width on images* doesn't work so I'd hazard a guess at not.


*Not that this is a hugely beneficial application. At all.
 
O

old.Kez

Guest
NN has supported Iframes since the 6 release, and opera, mozilla et al all also support the element, because its part of the 4.01 specs.

They're a crock of shit, though.
 
W

wyrd_fish

Guest
well, looks like I'm out of touch with these ofther browsers...

I only use them when I have to, ie. my web host has PHP set up not to run script inside include functions... witch is annoying
 
X

X10

Guest
Well I know it sounds old fashioned, but I'd like to be able to support as many browsers as possible, and I know you're going to say you can't support them all, which may be true depending on what kind of site you are creating, but I would certainly like to try to keep it as open to as many people as possible.
I myself until very recently was using NN4.7, until I moved to Opera 6. But if you are saying Frames is the way to go (Common support and from HTML 4.0) then I will go down that route, but no-one I have spoken to has ever recommended frames.

X10
 

Users who are viewing this thread

Top Bottom