the include statement
Moderator: General Moderators
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
the include statement
does it cause the entire page currently being viewed to load again?
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
example
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?:)
Code: Select all
<body>
blah blah blah
<?php
switch ($case)
{
case "blah":
include ("blah.php");
break;
}
?>
more blah htmlWhenever 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:
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:
I always see some form of this question about the include() family of statements, and this explanation always seems to help. 
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";
?>Code: Select all
<?php
// file3.php
echo "file 1 output\n";
if (isset($_GET['two'])) {
echo "file 2 output\n";
}
?>-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm