Click to See Complete Forum and Search --> : [RESOLVED] Opening the right page...
wwwfilmfilercom
Nov 23rd, 2006, 06:45 AM
hi sorry i'm a real newbie to php so would like to check this out:
my index.php page looks like this:
<body>
<div class="header">
<?php include ("header.html") ?>
</div>
<div id="menu">
<?php include ("menu_start.html") ?>
</div>
<div id="mainbody">
<?php include ("homebody.html") ?>
</div>
<div class="footer">
<?php include ("footer.html") ?>
</div>
so what i want to do is have a link called 'about' on my header.html page but when i click this i want to show 'about.html' in the same place as 'homebody.html' - how do i do this? ie. load a specific page in a specific part of the page?? :ehh:
thanks :thumb:
The Hobo
Nov 23rd, 2006, 10:24 AM
There are many ways you could do it. You could link to index.php?a=about, and then in your code do:
<div class="header">
<?php include ("header.html") ?>
</div>
<div id="menu">
<?php include ("menu_start.html") ?>
</div>
<div id="mainbody">
<?php if( isset( $_REQUEST[ "a" ] ) )
{
switch( $_REQUEST[ "a" ] )
{
case "about":
include ("about.html");
break;
default:
include ("homebody.html");
}
}
else
{
include ("homebody.html");
}
?>
</div>
<div class="footer">
<?php include ("footer.html") ?>
</div>
wwwfilmfilercom
Nov 23rd, 2006, 10:25 AM
hmmm, i'd have to put everything into the code there.. is there a way i can call that bit of the page 'mainbody' and then just call something to load the correct page into 'mainbody' - like you would with frames for instance??
The Hobo
Nov 23rd, 2006, 10:30 AM
What I would normally do is this have all HTML/PHP for the header and menu be in a file called header.php, and everything for the footer be in footer.php, so all I need to do on every page is:
<?php
require( "header.php" );
?>
<b>Content Here</b>
<?php
require( "footer.php" ):
?>
Notice that if you have many pages, you're going to have a lot of repetative code in each page.
I would move restructure it so all of this is in your header file:
<html>
<head>
...
</head>
<body>
<div class="header">
<?php include ("header.html") ?>
</div>
<div id="menu">
<?php include ("menu_start.html") ?>
</div>
<div id="mainbody">
I'd replace the include for "header.html" with the actual text, and save the lot as header.html.
And include the following in your footer:
</div>
<div class="footer">
<?php include ("footer.html") ?>
</div>
</body>
</html>
So that you can just include the header, have your content, and then include your footer like I showed in the example above. Much less repetative HTML that way, and much easier to manage when you want to change the layout.
The Hobo
Nov 23rd, 2006, 10:33 AM
hmmm, i'd have to put everything into the code there.. is there a way i can call that bit of the page 'mainbody' and then just call something to load the correct page into 'mainbody' - like you would with frames for instance??
You could use AJAX, but that'll take a little research and trial and error. Uses JavaScript to make a call to the webserver to retrieve the content. On the callback, you could just replace the content of a DIV with whatever the server returned.
If you're interested, I'd consider using the Prototype (http://prototype.conio.net/) library, or you could simply write your own JS code to do it.
wwwfilmfilercom
Nov 23rd, 2006, 10:36 AM
lol holy moly - i though php would be able to handle this but ill definitely look into the prototype library thanks!
The Hobo
Nov 23rd, 2006, 10:40 AM
Well, using AJAX just to simply go to a new page may not be the best use of AJAX. Most people would probably just do it by having multiple pages (index.php, about.php) and link to those...but if you don't want that, then yeah, look into AJAX.
If the page is already loaded, PHP is out of the equation. If you want to do something with the page after its loaded, you need something on the client-side. PHP is strictly server-side programming.
wwwfilmfilercom
Nov 24th, 2006, 06:01 PM
Right I'm stuck (again) and even though I've looked at SSI and using <include> or <require> I am having problems organising the structure of my page with PHP. Hopefully you can help:
The page is split into 4 sections:
header and footer always stay the same...
menu has the login form and when logged in shows member/admin links...
mainbody is where the content loads...
The bit thats most confusing is menu because I can get one part of the page to change, such as mainbody, but I'm wondering how to keep the menu bit the same whether the user has logged in or not...
How can I structure this page??
Please help!!
The Hobo
Nov 24th, 2006, 06:06 PM
Assuming you have some mechanism for determining whether or not someone is logged in, I would do something like this in the menu file:
<a href="">Home</a>
<?php
if( user_is_logged_in ) // obviously change this
{
?>
<a href="">Admin Option #1</a>
<a href="">Admin Option #2</a>
<?php
}
else
{
?>
<a href="">Login</a>
<?php
}
?>
<a href="">Something Else</a>
It really doesn't need to be any more complicated than that. You could also have two seperate files, admin_menu.html and standard_menu.html and include() or require() the file depending on whether or not the viewer is logged in.
wwwfilmfilercom
Nov 24th, 2006, 06:47 PM
So I would have:
<?php
require( "header.php" );
?>
<b>Content Here</b>
<?php
require( "footer.php" ):
?>
And in header.php:
<html>
<head>
...
</head>
<body>
<div class="header">
<?php include ("header.html") ?>
</div>
<div id="menu">
<?php include ("menu.php") ?>
</div>
And in menu.php:
<a href="">Home</a>
<?php
if( user_is_logged_in ) // obviously change this
{
<?php
require( "admin_menu.html" );
?>
}
else
{
<?php
require( "member_menu.html" );
?>
}
?>
<a href="">Something Else</a>
Is that correct???
The Hobo
Nov 24th, 2006, 10:51 PM
Um...you could do it like that, yes.
wwwfilmfilercom
Nov 25th, 2006, 05:41 PM
Thanks!!!!! I checked that out and it works great FINALLY I've worked this out lol...
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.