Page 1 of 1
the include statement
Posted: Thu Sep 29, 2005 7:25 pm
by Charles256
does it cause the entire page currently being viewed to load again?
Posted: Thu Sep 29, 2005 7:27 pm
by feyd
huh?
Posted: Thu Sep 29, 2005 7:30 pm
by Charles256
example
Code: Select all
<body>
blah blah blah
<?php
switch ($case)
{
case "blah":
include ("blah.php");
break;
}
?>
more blah html
after clicking a link to make case equal to blah does it then reload the html code on the page?or just insert the code from blah.php?:)
Posted: Thu Sep 29, 2005 7:39 pm
by feyd
both.
Posted: Fri Sep 30, 2005 1:18 pm
by Skara
Whenever a page loads, a page loads. php works like this:
1. user variables are defined (get, post, cookies, session, server).
2. it runs the script from top to bottom.
Examples:
Code: Select all
<?php
// file1.php
echo "file 1 output\n";
if (isset($_GET['two'])) {
include 'file2.php';
}
?>
Code: Select all
<?php
// file2.php
echo "file 2 output\n";
?>
When you include a file, it's the same thing as if that file were physically there. include() is there simply so you can split your code into separate files. The above two files are
exactly (sorta) like the following:
Code: Select all
<?php
// file3.php
echo "file 1 output\n";
if (isset($_GET['two'])) {
echo "file 2 output\n";
}
?>
I always see some form of this question about the include() family of statements, and this explanation always seems to help.

Posted: Fri Sep 30, 2005 1:41 pm
by Charles256
i was comparing the iframe to the include and it seems iframe would save loading time

Posted: Fri Sep 30, 2005 1:46 pm
by Skara
iframes aren't the best solution. Many users don't enable frames on webpages because they generally suck.
Posted: Fri Sep 30, 2005 1:50 pm
by Charles256
then i do the following .. <iframe blah>Enable frames or face dire consequences </iframe>
problem solved:)