Page 438 - Beginning PHP 5.3
P. 438

Part III: Using PHP in Practice
                    $rowCount = 0;

                    foreach ( $logEntries as $logEntry ) {
                      $rowCount++;
                    ? >
                           < tr < ?php if ( $rowCount % 2 == 0 ) echo ‘ class=”alt”’ ? > >

                             < td > < ?php echo $logEntry- > getValueEncoded( “pageUrl” ) ? > < /td >



                             < td > < ?php echo $logEntry- > getValueEncoded( “numVisits” ) ? > < /td >

                             < td > < ?php echo $logEntry- > getValueEncoded( “lastAccess” ) ? > < /td >


                           < /tr >
                      < ?php
                    }
                    ? >
                         < /table >

                         < div style=”width: 30em; margin-top: 20px; text-align: center;” >
                           < a href=”javascript:history.go(-1)” > Back < /a >
                         < /div >

                      < ?php
                    displayPageFooter();

                    ? >
                   This script expects to be passed a  memberId  query string parameter specifying the member to be
                 displayed. This value is then passed to   Member::getMember()  to retrieve the record as a  Member  object.
                 If nothing is returned from the call to   getMember() , the member could not be found in the  members
                table, so an error message is displayed and the script exits.
                  Assuming the member was found and retrieved, the script then calls   LogEntry::getLogEntries() ,
                 again passing in the member ID, in order to retrieve the rows in the   accessLog  table associated with
                this member (if any).
                  Next, the script displays all of the member fields inside an HTML definition list (  dl ) element. Mostly this
                is simply a case of calling   Member::getValueEncoded()  for each field, passing in the name of the field
                 to retrieve, and displaying the returned value. For the special cases of gender and favorite genre, the
                   getGenderString()  and  getFavoriteGenreString()  methods are called to display the field values
                in a more human - friendly format.

                  After the member details come the access log entries. These are displayed in a similar way to the
                members in the   view_members.php  script. For each log entry, the page URL, number of visits, and last
                 access date are displayed in a table row. Finally, at the end of the page, a JavaScript link is created to
                 allow the user to go back to the member list page.

                  Testing the Application

                   Now that you ’ ve created all the scripts for the application, it ’ s time to try it out. Open the  view_
                 members.php  script ’ s URL in your Web browser. You should see a page similar to Figure 13 - 1. Try
                 moving through the pages (there should be two) using the “Next page” and “Previous page” links, and
                 changing the sort order by clicking the column headings.





              400





                                                                                                      9/21/09   9:12:07 AM
          c13.indd   400
          c13.indd   400                                                                              9/21/09   9:12:07 AM
   433   434   435   436   437   438   439   440   441   442   443