PHP is parsed on the server when the web page is requested by the browser. The resultant content is sent to the browser. For the example you show, the browser would receive -

<div id="page1" style="display:none;">Whatever HTML content page1.php generated</div>Just because you are using javascript to change the display status of this, the content is already present within the div tags and has already been received by the browser, the same as if the content was directly coded within the HTML of the web page instead of the result of a PHP include statement.

aprestong

01-31-2007, 09:48 PM

Thanks, CFMaBiSmAd -
That makes perfect sense and I feel like an idiot now...
This makes me wonder -
I was going to include 18 separate pages and hide them - then use the a javascript show / hide layer script in a menu to show the content without having to do a whole page reload....

Even though there will be just a little text and maybe a few graphics in each layer, it probably doesnt make much sense to have all those includes....
Am I right to assume this?

In a sense, I will have to load all 18 of these pages right away before anything will work, right?

Would you say I'd be better off the old fashioned way and having a separate page for each link?

aedrin

01-31-2007, 10:12 PM

From the sounds of it, it would indeed be a better idea to resort to the single page.

There is almost never a reason to load more than 1 page at a time.

The only time it would make sense if for example you have a FAQ page, and you hide the answers by default, and then show them as they click on a link.

felgall

01-31-2007, 10:17 PM

You could use AJAX to progressively retrieve the content of hidden sections so that they wouldn't slow the initial display of the page but would hopefully be there by the time that the appropriate section was displayed. You would need an alternate method of displaying each one separately for when Javascript isn't available though.

if(!empty($_GET['page']))
{
if(array_key_exists($_GET['page'], $pages))
{
foreach($pages as $pageid => $pagename)
{
if($_GET['page'] == $pageid && file_exists($pagename))
{
/* if somebody's making a request for ?page=xxx and
the page exists in the $pages array, we display it
checking first it also exists as a page on the server */
include $pagename;
}
} // end foreach
}
}

Notice that I added

if(!empty($_GET['page']))
{
}

around the content section because I was getting a
"Notice: Undefined index: page" on this line:

if(array_key_exists($_GET['page'], $pages))

Thanks for your help! This is a really great method.... no javascript!