A Working Example
In this section, we use some of the techniques described so far to develop a simple, complete PHP script. The script doesn't process input from the user, so we leave some of the best features of PHP as a web scripting language for discussion in later chapters.
Our example is a script that produces a web page containing the times tables. Our aim is to output the 1-12 times tables. The first table is shown in Figure 2-2 as rendered by a Mozilla browser.
Figure 2-2. The output of the times-tables script rendered in a Mozilla browser
The completed PHP script and HTML to produce the times tables are
shown in Example 2-4. The
first ten lines are the HTML markup that produces the <head>
components and the <h1>The Times Tables</h1>
heading
at the top of the web page. Similarly, the last two lines are HTML that
finishes the document: </body>
and </html>
.
Between the two HTML fragments that start and end the document is
a PHP script to produce the times-table content and its associated HTML.
The script begins with the PHP open tag <?php
and finishes with the close tag
?>
.
Example 2-4. A script to produce the times tables
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>The Times-Tables</title> </head> <body bgcolor="#ffffff"> <h1>The ...
Get Web Database Applications with PHP and MySQL, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.