BYO Database Websites PHP Templates

At the end of Chapter 3 in Kevin Yank’s BYO Database Driven Websites he talks about using PHP templates.

I don’t follow what the include statement actually does since when I open the directory of http://localhost/count10 it will just display the index.php file.

When I open the “template” file it shows nothing. I feel like I’m missing something, like the bigger picture. Shouldn’t count.html.php be the index.

Any help would be great


Thanks for your reply bro.

Yea I kinda understand it more, was thinking about it during the day and thinking about it too much as if it was like including javascript or css in the page.

I find with learning any new skill it takes awhile to get your head round it but eventually you get it.

Now if I could just get the mysqli_connect to work! ha (see my other post)


Using include (and require) is like telling PHP to “put these together as though they were one big file”. So you can have a “skeleton” file that includes different things lile “if page request is Contact include contact.php” or “if page request is Welcome include welcome.php” etc. without needing to have the same “skeleton” code in more than one file. Much easier to make changes in one file than making the same changes in a bunch of “hard-coded” pages.

You say when you open the “template” it shows nothing. I think if you look closely you’ll see that your browser’s title bar will say something like “Form Example” and if you look in the pages view-source you’ll see

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="" xml:lang="en" lang="en">
<title>Form Example</title>
<meta http-equiv="content-type"
content="text/html; charset=utf-8"/>

The template has PHP in it

<?php echo $output; ?>

but if the variable $output hasn’t been assigned a value in any previous code there will be nothing to echo.

The “pieces” need the others to work correctly. You can’t really look at one part and see the same as you would see as a whole.