Page 1 of 1

Including Pieces of Code

Posted: Thu Nov 25, 2010 9:45 am
by Pazuzu156
I want to include only a small portion of code. When I use include(), it puts the entire page I include and shows up. I only want to show a table from one page, on the new one. How would I do this?

Re: Including Pieces of Code

Posted: Thu Nov 25, 2010 10:17 am
by Regicollis
The include command will include the entire file.

If you want to use the same table in multiple files you can put the table (And only the table) in a separate file and use the include command on all pages you want the table to be on. The "table.php" (or whatever name you want) file should look like this:

Code: Select all

<table>
    <tr>
        <td>This is where the content of the table goes</td>
    </tr>
</table>
i.e. no other markup than the one creating the table.

Then you use

Code: Select all

<?php include "table.php";?>
on the pages where you would like your table to appear.