PHP105 and a half

From mi-linux
Revision as of 11:33, 19 February 2007 by In6480 (talk | contribs)
Jump to navigationJump to search

A word about include statements

A useful function in PHP is to include the contents of fileX in fileY at a given point.

For example:

  • You could
    • include a menu file in each page
    • or a CSS file dynamically created from a database
    • or any number of other ideas

Create the following file and save it as "menu.php"

 <table border=1>
   <tr>
     <td><a href="page1.php">Page 1</a></td>
     <td><a href="page2.php">Page 2</a></td>
     <td><a href="page3.php">Page 3</a></td>
  </tr>
 </table>

Now create the following and save it as "page1.php"

 <html><head><title>Page1</title></head>
 <body>
 <? include ("menu.php"); ?>
 <p>this is the content of page 1</p>
 </body>
 </html>


Now create the following and save it as "page2.php"

 <html><head><title>Page2</title></head>
 <body>
 <? include ("menu.php"); ?>
 <p>this is the content of page 2</p>
 </body>
 </html>

See if you can create the third page??

Ready to move on?

PHP106 - Flow Control - Selection