shinichi♥stranger
carol♥z-motion
aquila♥(inky);paper
map♥swordmanspirit

PHP tutorials: Include

Level:
The include-function is the most easiest way to get into PHP if you haven't had some experience with it yet. This turorial will give you a short but effective introduction by explaining how to get your table layout run with PHP.
Please mind that using table layouts is not the right way to present your contents on the Internet unless you offer simple data and numbers. The best way is code your layout CSS based. But if you don't know how to code that table will be just fine for you.
Today's schedule is to code a four area table layout which conforms to the content (major text and sub-pages). In short: If you activate a link at the navigation/ menue the table will conform to the content and the table pulls under. Best example is Grieved-Lightness - you need to scroll all way to down to read the last sentence.

1. Create a html-document and an ordinary table

First of all you have to create a new HTML-document and a table within that consist of three raws and two column as pictured on the example. If you do so your table should look similar to this one:
<table width="60%" border="0">
<tr>
<td colspan="2"><!--HEADER--></td>
 </tr>
 <tr>
 <td width="60%">
 
<!--CONTENT-->
Welcome to this tutorial about incl....

</td>
<td width="40%">
<!--NAVIGATION-->
<a href="#">Link</a><br>
<a href="#">Link</a>
</td>
</tr>
<tr>
<td colspan="2"><!--FOOTER --></td>
</tr>
</table>
The code <td colspan="2"> means that two colums became one and you got one column instead of two. In this example this happened to the header and footer colums. This way you get more space for text and images without need to cut them. Codes which look like <!--BLA--> are simple annotation and don't have any influence with the final result.

2. Seperate code

For the include-funktion we need to cut the layout into three pieces: header (red code), content (yellow code) and footer (blue code). Make sure to save these pieces as header.php, index.php and footer.php. The basic idea is to build a (table) frame around your contents. You can tell that from just looking at the code above. To do it right you need to save the everthing that's in front of your content as header.php and everything that follows as footer.php. If you do so your PHP-documents should look like this:
header.php:

<table width="60%" border="0">
<tr>
<td colspan="2"><!--HEADER--></td>
 </tr>
 <tr>
 <td width="60%">
 
index.php:

<!--CONTENT-->
Welcome to this tutorial about incl....
footer.php:

</td>
<td width="40%">
<!--NAVIGATION-->
<a href="#">Link</a><br>
<a href="#">Link</a>
</td>
</tr>
<tr>
<td colspan="2"><!--FOOTER --></td>
</tr>
</table>

3. the unbelievable-amazing-and-allmighty Include-function

Let's leave it at that and let's have a closer look at the index.php which now contents your contens (a very confusing sentence :|). Your layout is now seperated into three pieces but they won't work like this together. You still need to INCLUDE your content between header and footer:
index.php:

<?php include('header.php');?>
      <!--CONTENT-->
      Welcome to this tutorial about incl....
<?php include('footer.php');?>
Did I promise too much? I guess not since the include-funtion is as easy as useful. Do this with all of your sub-pages and you don't need to be afraid of too long text anymore :) Remember to address the sub-page directly if you want to link to a specific one and leave the target blank. Just type <a href="index.php">index</a> and do not link to header.php or footer.php since those pages will just be displayed relating to sub-pages which are included between them.
Just one little hint at least: Adobe Dreamweaver CS4 displays included documents if you open a sub-page.
last updated on February 4, 2010
⬅ GO BACK

general

style selection

broad your mind

creative aids