PHP and MySQL Web Development - P25: PHP and MySQL Web Development teaches the reader to develop dynamic, secure, commercial Web sites. Using the same accessible, popular teaching style of the first edition, this best-selling book has been updated to reflect the rapidly changing landscape of MySQL and PHP. | Loading Arrays from Files 87 Listing Using PHP to Display Orders for Bob php create short variable name DOCUMENT_ROOT HTTP_SERVER_VARS DOCUMENT_ROOT orders file DOCUMENT_ROOT . orders number_of_orders count orders if number_of_orders 0 echo p strong No orders pending. Please try again later. strong p for i 0 i number_of_orders i echo orders i . br This script produces almost exactly the same output as Listing in the previous chapter which is shown in Figure time we are using the function file which loads the entire file into an array. Each line in the file becomes one element of an array. This code also uses the count function to see how many elements are in an array. Furthermore we could load each section of the order lines into separate array elements to process the sections separately or to format them more attractively. Listing does exactly that. Listing Using PHP to Separate Format and Display Orders for Bob php create short variable name DOCUMENT_ROOT HTTP_SERVER_VARS DOCUMENT_ROOT html head title Bob s Auto Parts - Customer Orders title head body h1 Bob s Auto Parts h1 h2 Customer Orders h2 php Read in the entire file. Each order becomes an element in the array orders file DOCUMENT_ROOT . orders count the number of orders in the array 88 Chapter 3 Using Arrays Listing Continued number_of_orders count orders if number_of_orders 0 echo p strong No orders pending. Please try again later. strong p echo table border 1 n echo tr th bgcolor CCCCFF Order Date th th bgcolor CCCCFF Tires th th bgcolor CCCCFF Oil th th bgcolor CCCCFF Spark Plugs th th bgcolor CCCCFF Total th th bgcolor CCCCFF Address th tr for i 0 i number_of_orders i split up each line line explode t orders i keep only the number of items ordered line 1 intval line 1 line 2 intval line 2 line 3 intval line 3 output each order echo tr td line 0 td td align right line 1 td td align right line 2 td td align right line 3 td