Including Pieces of Code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Pazuzu156
Forum Contributor
Posts: 241
Joined: Sat Nov 20, 2010 9:00 pm
Location: GA, USA
Contact:

Including Pieces of Code

Post 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?
- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
Regicollis
Forum Newbie
Posts: 8
Joined: Thu Nov 25, 2010 8:51 am

Re: Including Pieces of Code

Post 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.
Post Reply