Difference between revisions of "PHP105 and a half"
From mi-linux
Jump to navigationJump to searchm (PHP105.5 moved to PHP105 and a half) |
|||
Line 10: | Line 10: | ||
** or any number of other ideas | ** or any number of other ideas | ||
− | + | Create the following file and save it as "menu.php" | |
+ | <nowiki> | ||
+ | <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></nowiki> | ||
− | <nowiki>include (" | + | Now create the following and save it as "page1.php" |
+ | <nowiki> | ||
+ | <html><head><title>Page1</title></head> | ||
+ | <body> | ||
+ | <? include ("menu.php"); ?> | ||
+ | <p>this is the content of page 1</p> | ||
+ | </body> | ||
+ | </html></nowiki> | ||
+ | |||
+ | |||
+ | Now create the following and save it as "page2.php" | ||
+ | <nowiki> | ||
+ | <html><head><title>Page2</title></head> | ||
+ | <body> | ||
+ | <? include ("menu.php"); ?> | ||
+ | <p>this is the content of page 2</p> | ||
+ | </body> | ||
+ | </html></nowiki> | ||
+ | |||
+ | See if you can create the third page?? | ||
+ | |||
+ | ==Ready to move on?== | ||
+ | [[PHP106|PHP106 - Flow Control - Selection]] |
Revision as of 10:33, 19 February 2007
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??