PHP question

Browni

Registered
Right, i would like the simplicity of a iframe situation with changing content e.g. click link in nav bar, and it appears in main section, but in PHP, i know how to use the <?php include ('filename.html') > is there any way i can specify that a area of the page is called 'content' and point a file to to display in that area? like the way Mabmbo OS does it (and many other CMS's)\

Browni
 
Im assuming you mean without reloading the whole page right? If so, not really no. Youd either have to use frames, iframes or div's. DIV's using css visibilty is a wicked way of doing this but the issue is that you need to load the content of all divs on page load, you cannot load any external files into divs.

Php is a server side language so the whole page has to be reloaded fromthe server is order to have an include work properly. Easiest way to do what you want is using an iframe (if you want to load external files.)

This is how I built my site
 
What you're describing is completely possible, but not if you don't want to reload the entire page, like andehlu said. If you would like me to collaborate with you and try to figure out a solution, send me an IM; my screen name's in my profile.
 
I have the same problem as Browni but i'm not bothered if the whole page reloads. the code i'm using is: in the area i want the content to appear:

<?php if (!$t) {
include("home.php");
} else {
include($t);
}?>

And on the nav bar button:

<a href="?t=creative.php">

and so on.

This is working fine on my Mac at work, BUT if I upload it to my ISP or even put it onto any another Mac on the network or at home, it does not work at all. Anyone have anyi deas why?

to see an example go to sample I have only coded the first 2 buttons in the nav bar so far. I can assure you this works perfect on my Mac at work.

If i cannot get this to work, then, How do I use iFrames???

Thanks in advance
 
They probably have Register Globals turned off. Try if(!$_GET['t']) instead. Or, declare beforehand: $t = $_GET['t'];
 
Arden said:
They probably have Register Globals turned off. Try if(!$_GET['t']) instead. Or, declare beforehand: $t = $_GET['t'];
Arden.
THANKS, this works fine now. You are a superstar!!!!!
 
A question for Arden (or any other php coder that can help)

I used the code Arden sugested on a site and it works perfect. Now I have used the same code (well almost the same, changed t for x) on another site. the code works fine BUT the server that hosts it has a high level of reporting turned on and I get the following message appear:

Notice: Undefined index: x in E:\web\trix-ltd\matrix\index.php on line 92

line 92 is the first line of the following php code"

<?php if (!$_GET['x']) {
include("home.php");
} else {
include($x.'.php');
}?>


The ISP will not turn reporting off. Is there any way to stop this from appearing??

the site it's on is
www.matrixfm.com

THANKS
 
Try intercepting and managing the error yourself.

PHP:
error_reporting(); 
set_error_handler(myError);

Put the above code in your php and write a function called myError to act on the error message.

In think that in your example the
PHP:
include($x.'.php');
is causing the problem as variable $x is undefined.
 
aicul is correct. When you say:

Code:
$_GET['x']

...it's throwing an error, because there is no 'x' index in $_GET. What you want to do is trap that. Here's what I would do:

Code:
$page_to_display = isset($_GET['x']) ? $_GET['x'] : 'home';
  include( $page_to_display . '.php' );

What this does is first check if there is an 'x' index set in $_GET. If there is, it uses it. Otherwise, it uses 'home'. Once you have that, you can use it to do your include.
 
Back
Top