Page 425 - Beginning PHP 5.3
P. 425

Chapter 13: Retrieving Data from MySQL with PHP
                            ❑       PAGE_SIZE  specifies how many member records are shown on any one page
                            ❑       TBL_MEMBERS  holds the name of the members table in the database. It ’ s a good idea to place
                                strings like this in constants, rather than hard - coding them in the application code, in case you
                                need to change table names at a later date
                            ❑       TBL_ACCESS_LOG  holds the name of the access log table

                               In a live server environment, you should store the file containing your database username and password
                             outside your document root folder, if possible, to avoid any chance of the username and password being
                             viewed by a visitor to the site.

                           Creating the common.inc.php File

                           The second file to create is also simple. It contains common utility functions that are used throughout
                         this application. The functions are   displayPageHeader() , which outputs the standard XHTML page
                          header for the application (including the page title, passed in as an argument), and
                            displayPageFooter() , which outputs the XHTML markup that appears at the bottom of each page.

                            Save this file as   common.inc.php  in your  book_club  folder.
                               < ?php

                             function displayPageHeader( $pageTitle ) {
                             ? >
                               < !DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
                              “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd” >
                               < html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en” >
                                < head >

                                  < title > < ?php echo $pageTitle? > < /title >

                                  < link rel=”stylesheet” type=”text/css” href=”../common.css” / >
                                  < style type=”text/css” >
                                   th { text-align: left; background-color: #bbb; }
                                   th, td { padding: 0.4em; }
                                   tr.alt td { background: #ddd; }
                                  < /style >
                                < /head >
                                < body >

                                  < h1 > < ?php echo $pageTitle? > < /h1 >


                               < ?php
                             }

                             function displayPageFooter() {
                             ? >
                                < /body >
                               < /html >
                               < ?php
                             }
                             ? >






                                                                                                         387





                                                                                                      9/21/09   9:12:02 AM
          c13.indd   387
          c13.indd   387                                                                              9/21/09   9:12:02 AM
   420   421   422   423   424   425   426   427   428   429   430