PHP Application Overview and Example May 27, 2004 Presented By: Mark Armstrong and Marc Saccucci.

Slides:



Advertisements
Similar presentations
PHP: Date() Function The PHP date() function formats a timestamp to a more readable date and time.
Advertisements

PHP I.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
The Web Warrior Guide to Web Design Technologies
PHP (2) – Functions, Arrays, Databases, and sessions.
World Wide Web1 Applications World Wide Web. 2 Introduction What is hypertext model? Use of hypertext in World Wide Web (WWW) – HTML. WWW client-server.
Intermediate PHP & MySQL
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
FILE UPLOADS CHAPTER 11. THE BASIC PROCESS 1.The HTML form displays the control to locate and upload a file 2.Upon form submission, the server first stores.
MS3304: Week 4 PHP & HTML Forms. Overview HTML Forms elements refresher Sending data to a script via an HTML form –The post vs. get methods –Name value.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
PHP == ‘ Hypertext Preprocessor ’ Open-source, server-side scripting language Used to generate dynamic web-pages PHP scripts reside between reserved PHP.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
(c) Manzur Ashraf, Short course, KFUPM PHP & MySQL 1 Basic PHP Class 2.
INTERNET APPLICATION DEVELOPMENT For More visit:
Lab Assignment 7 | Web Forms and Manipulating Strings Interactive Features Added In this assignment you will continue the design and implementation of.
Lecture 7 – Form processing (Part 2) SFDV3011 – Advanced Web Development 1.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
School of Computing and Information Systems CS 371 Web Application Programming PHP - Basics Serving up web pages.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
Nael Alian Introduction to PHP
PHP meets MySQL.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Using Client-Side Scripts to Enhance Web Applications 1.
PHP - Basic Language Constructs CSCI 297 Scripting Languages - Day Two.
Website Development with PHP and MySQL Saving Data.
VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.
PHP2. PHP Form Handling The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. Name: Age:
ITCS373: Internet Technology Lecture 5: More HTML.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
PHP. What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server.
Introduction to PHP Advanced Database System Lab no.1.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP supports.
PHP Open source language for server-side scripting Works well with many databases (e.g., MySQL) Files end in.php,.php3 or.phtml Runs on all major platforms.
3 1 Sending Data Using an Online Form CGI/Perl Programming By Diane Zak.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Server-Side Scripting with PHP ISYS 475. PHP Manual Website
Introduction to PHP.
Forms Collecting Data CSS Class 5. Forms Create a form Add text box Add labels Add check boxes and radio buttons Build a drop-down list Group drop-down.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
©SoftMooreSlide 1 Introduction to HTML: Forms ©SoftMooreSlide 2 Forms Forms provide a simple mechanism for collecting user data and submitting it to.
 2001 Prentice Hall, Inc. All rights reserved. Chapter 7 - Introduction to Common Gateway Interface (CGI) Outline 7.1Introduction 7.2A Simple HTTP Transaction.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
20-753: Fundamentals of Web Programming 1 Lecture 6: Advanced HTML Fundamentals of Web Programming Lecture 6: Advanced HTML.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
CGS 3066: Web Programming and Design Spring 2016 PHP.
PHP WORKSHOP (Session 1) INFO 257 Supplement. Outline What is PHP ? PHP Language Basics PHP Exercise.
A pache M ySQL P hp Robert Mudge Reference:
Web Database Programming Using PHP
Web Database Programming Using PHP
PHP Introduction.
Intro to PHP & Variables
PHP.
Lecture 5: Functions and Parameters
Tutorial 6 PHP & MySQL Li Xu
PHP-II.
Presentation transcript:

PHP Application Overview and Example May 27, 2004 Presented By: Mark Armstrong and Marc Saccucci

PHP Benefits Not proprietary Not proprietary Fast % faster then other HTML embedded scripting (CGI) Fast % faster then other HTML embedded scripting (CGI) Stable Stable Familiar – syntactically similar to Java/Perl/C/C++ Familiar – syntactically similar to Java/Perl/C/C++ Compatible with nearly all platforms Compatible with nearly all platforms Dynamic Dynamic

How PHP Works Uses Apache Web Server, which handles HTTP requests and sends HTML responses to the browser. Uses Apache Web Server, which handles HTTP requests and sends HTML responses to the browser. Apache can be configured to render.php files as HTML. Apache can be configured to render.php files as HTML.

Dynamic Applications Database access (MySQL, INFORMIX, Oracle, etc) Database access (MySQL, INFORMIX, Oracle, etc) Text File I/O Text File I/O XML XML Parsing other websites Parsing other websites

PHP vs. CGI Embedded in HTML Code Embedded in HTML Code All code in one location All code in one location Fast Fast Scaleable Scaleable Not compiled Not compiled Separate CGI script loaded for each request, called by HTML page Separate CGI script loaded for each request, called by HTML page Slow Slow Not very scaleable Not very scaleable

PHP Syntax Start and end tags needed: Start and end tags needed:<?php PHP Code Here; PHP Code Here;?> Syntactically very close to C Syntactically very close to C Semicolon after each PHP statement Semicolon after each PHP statement Comments start with // or # Comments start with // or # Variables preceded with a $ Variables preceded with a $ Can be object oriented Can be object oriented

GET and POST Form Actions Used to pass information to a page Used to pass information to a page POST method is used when passing ‘hidden’ information via forms POST method is used when passing ‘hidden’ information via forms GET method is used to create a query string which passes variables via the URL GET method is used to create a query string which passes variables via the URL POST can pass an unlimited amount of data POST can pass an unlimited amount of data GET can only pass up to a 1,000 character query string GET can only pass up to a 1,000 character query string

Query Strings Use the GET method to pass query strings via the URL. Use the GET method to pass query strings via the URL. - Example: $_GET[“page”]=1 and $_GET[“element”]=Wx is used in the php code to grab the page number and weather element type from the URL above.

Example Application of PHP Main Code: display_consistency.php <html><head> Consistency Summary Page Consistency Summary Page </head> Description: First, we’ll create the basic HTML header and open the php code block with the <?php to include the header for the page. First, we’ll create the basic HTML header and open the php code block with the <?php to include the header for the page.

display_consistency.php - continued <?php/******************************** * This page displays consistency data * This page displays consistency data for the specified day, neighboring wfo for the specified day, neighboring wfo or element specified as spec in the or element specified as spec in the querystring, and the wfo sent in the querystring, and the wfo sent in the querystring. querystring.********************************/ // Set up basic parameters and querystring values. // Set up basic parameters and querystring values. $cycle = "hourly"; // variables are always preceded by a $ $cycle = "hourly"; // variables are always preceded by a $ $wfo=$_GET["wfo"]; // $_Get array contains the form values $wfo=$_GET["wfo"]; // $_Get array contains the form values $spec=$_GET["spec"]; // _GET method and querystrings. $spec=$_GET["spec"]; // _GET method and querystrings. // Set the region based on the WFO ID. // Set the region based on the WFO ID. // The substr function retrieves a substring of the string variable // The substr function retrieves a substring of the string variable // passed in. In this case, the first character from $wfo is extracted. // passed in. In this case, the first character from $wfo is extracted. if ((substr($wfo,0,1) == "K") || $wfo == "CONUS") if ((substr($wfo,0,1) == "K") || $wfo == "CONUS") $region="CONUS"; $region="CONUS"; else else $region="ALASKA"; $region="ALASKA"; Description: Open PHP using: <?php, and start to set some of the variables that will be needed. Open PHP using: <?php, and start to set some of the variables that will be needed. We fetch the “wfo” and “spec” parameters from the querystring. We fetch the “wfo” and “spec” parameters from the querystring. Notice the C-style comments and if construct Notice the C-style comments and if construct

display_consistency.php - continued // Set up arrays for menu bar items… // Set up arrays for menu bar items… // using the array() function is one way to // initialize arrays $elementList=array("MaxT","MinT","PoP12","QPF", "Sky","SnowAmt","T","Td","WaveHeight", "WindDir","WindSpd"); "WindDir","WindSpd");$day_list=array("Day0","Day1","Day2","Day3", "Day4","Day5","Day6","Day7"); "Day4","Day5","Day6","Day7"); // Like most scripting languages, PHP can use the // echo command to output data. // PHP also uses C output commands as well. // The "." concatenates strings echo " Consistency Summary for the $cycle cycle for ". $wfo. " \n"; echo " \n"; Description: Next we set up some arrays using the array() function. Next we set up some arrays using the array() function. We then use php to echo some html code. There is a shortcut for writing out larger blocks of HTML code, or we could just close the PHP block and reopen it after the HTML is written. We then use php to echo some html code. There is a shortcut for writing out larger blocks of HTML code, or we could just close the PHP block and reopen it after the HTML is written. We copy the correct array to the menu_array when we determine what ‘spec’ is. We copy the correct array to the menu_array when we determine what ‘spec’ is.

display_consistency.php - continued // Include function to determine a WFO // Include function to determine a WFO // list for the menu. // list for the menu. // The source code for any function that you // The source code for any function that you // want to use must be included before you call // want to use must be included before you call // the function. // the function. include ("get_wfo_list.php"); include ("get_wfo_list.php"); // Select which menu array to display // Select which menu array to display // Arrays may simply be assigned to each // Arrays may simply be assigned to each // other as in the next few lines. // other as in the next few lines. if (substr($spec,0,1) == "D") if (substr($spec,0,1) == "D") $menu_array=$day_list; $menu_array=$day_list; else if (substr($spec,0,1) == "K" || substr($spec,0,2) == "PA") else if (substr($spec,0,1) == "K" || substr($spec,0,2) == "PA") $menu_array=get_wfo_list($wfo); $menu_array=get_wfo_list($wfo); else else $menu_array=$elementList; $menu_array=$elementList; Description: We copy the correct array to the menu_array when we determine what spec is. We copy the correct array to the menu_array when we determine what spec is.

display_consistency.php – continued // Display the menu bar and highlight the // current WFO/Element/Day // the count() function returns the array length echo " \n "; for ($i=0; $i<count($menu_array); $i++){ if ($spec == $menu_array[$i]){ echo " "; echo " "; } else{ else{ echo " "; echo " "; } echo " " echo " ". $menu_array[$i]. " \n";. $menu_array[$i]. " \n"; } // End of for loop } // End of for loop echo " \n"; echo " \n"; Description: Now we create a small, one-row table to display the “menu”. Now we create a small, one-row table to display the “menu”. We start by using PHP to echo out the table header. We start by using PHP to echo out the table header. We then loop through the menu array that we assigned earlier. If the current spec is the same as the array element, then it is highlighted so we know which Day/WFO/element we are looking at. We then loop through the menu array that we assigned earlier. If the current spec is the same as the array element, then it is highlighted so we know which Day/WFO/element we are looking at. We create a link for each item in the menu array. The link is the name of this PHP page, with the spec set to each item in the menu array. We create a link for each item in the menu array. The link is the name of this PHP page, with the spec set to each item in the menu array. Lastly, we close the row and the table. Lastly, we close the row and the table.

display_consistency.php - continued // Include function that reads the consistency file and // loads the values. include("readConsistencyFile.php"); // Here, we cut some corners for this function. We use // the wfo name and cycle identifier to specify a file that // this function reads. Then we return the information // read here to global variables specified in the function. $status=readConsistencyFile($wfo,$cycle); $status=readConsistencyFile($wfo,$cycle); if($status == -1) if($status == -1) echo "Error on page. Please try again"; echo "Error on page. Please try again"; else if ($status == -10) else if ($status == -10) echo " No valid data for this echo " No valid data for this element at this time“. " \n"; element at this time“. " \n"; else{ else{ echo " Click on each Column Heading “. "to Sort by that Item \n"; echo " Click on each Column Heading “. "to Sort by that Item \n"; echo " " echo " ". "Explanation of statistics and methodolgy used. \n";. "Explanation of statistics and methodolgy used. \n"; // Include segment of code to display the sortable tables // Include segment of code to display the sortable tables // This is just a large repetitive section of code that // This is just a large repetitive section of code that // was easier to keep in its own.php file and include it // was easier to keep in its own.php file and include it // when needed. // when needed. include("HourlyTables.php"); include("HourlyTables.php"); } ?> // Close PHP section Description: We need to use a function to read the text file that contains the data. To do this, we need to include the function’s source code. We need to use a function to read the text file that contains the data. To do this, we need to include the function’s source code. Then, we call the function and pass in two input variables and assign the functions return value to $status for error checking. Then, we call the function and pass in two input variables and assign the functions return value to $status for error checking. If there is an error, we output a message to the browser. If there is an error, we output a message to the browser. Then we write out some basic text to the screen. Then we write out some basic text to the screen. The include at the bottom of the page is simply a space-saver. There are a number of lines of code, which are rather repetitive, which I just dumped into an include file. The include at the bottom of the page is simply a space-saver. There are a number of lines of code, which are rather repetitive, which I just dumped into an include file.

display_consistency.php - continued Table Created: Table Created: // Display the time that the table was created. // Display the time that the table was created. <?php <?php $inc_fname="CONTENTS/". $region. "_hourly_stats_time.php"; $inc_fname="CONTENTS/". $region. "_hourly_stats_time.php"; include($inc_fname); include($inc_fname); ?> ?> </tr><tr> </tr></table></body></html> Description: At the end of the page, we have a small table that displays the page’s creation time. At the end of the page, we have a small table that displays the page’s creation time. The PHP script includes the “hourly_stats_time.php” file, which just contains the generation time. The PHP script includes the “hourly_stats_time.php” file, which just contains the generation time. At the very end, the “footer.php” file is included. This contains the generic footer information. At the very end, the “footer.php” file is included. This contains the generic footer information. We then close the HTML like we normally do. We then close the HTML like we normally do.

Function: readConsistencyFile.php <?php function readConsistencyFile($wfo_id,$cycle){ // These are the global variables alluded to elsewhere. global $wfo2, $element, $day, $validTime, $numPts, $thresh, $elevDiff, $avgDiff, $bias, $offset1, $offset2, $mosaicImgName, $discImgName, $facefile, $element; $facefile, $element; if ($cycle == "hourly"){ $filename=$cycle. "/". $wfo_id. "_consistency.php"; $filename=$cycle. "/". $wfo_id. "_consistency.php";}else{ $filename=$cycle. "/".$wfo_id."_".$cycle. "_consistency.html"; $filename=$cycle. "/".$wfo_id."_".$cycle. "_consistency.html";} // Once again, this is the same type of format as C. // $fp is a file pointer that is returned with a value of // NULL if the file cannot be opened. // Here, we open $filename for reading. $fp=fopen($filename,"r"); if (!$fp) return -1; return -1; Description: The function declaration is basically the same as C, without the variable types. The function is contained in the {}. The function declaration is basically the same as C, without the variable types. The function is contained in the {}. Like other languages, we can declare function variables as global, meaning they can be used anywhere else without passing them in and out of the function. This was done here simply for convenience. Like other languages, we can declare function variables as global, meaning they can be used anywhere else without passing them in and out of the function. This was done here simply for convenience.

readConsistencyFile.php – continued $i=0; $i=0; // We read from this file until there is no more data // We read from this file until there is no more data while(!feof($fp)){ while(!feof($fp)){ if ($cycle == "hourly"){ if ($cycle == "hourly"){ // read 5 strings, 1 int, 4 floats, // read 5 strings, 1 int, 4 floats, // 2 ints and 2 strings from this row // 2 ints and 2 strings from this row $line=fscanf($fp,"%s%s%s%s%s%d%f%f%f%f%d%d%s%s"); $line=fscanf($fp,"%s%s%s%s%s%d%f%f%f%f%d%d%s%s"); // If we can't read this data, continue to the next iteration // If we can't read this data, continue to the next iteration if ($line == NULL) if ($line == NULL) continue; continue; // list takes line and assigns each value to the specified variable. // list takes line and assigns each value to the specified variable. // We load the associative array elements for sorting purposes later // We load the associative array elements for sorting purposes later list($wfo2_row, $element_row, $day_row, $ymd_row, $hr_row, $numPts["n$i"], $thresh["n$i"], $elevDiff["n$i"], $avgDiff["n$i"], $bias["n$i"], $offset1["n$i"], $offset2["n$i"], mosaicImgName["n$i"], $discImgName["n$i"]) = $line; list($wfo2_row, $element_row, $day_row, $ymd_row, $hr_row, $numPts["n$i"], $thresh["n$i"], $elevDiff["n$i"], $avgDiff["n$i"], $bias["n$i"], $offset1["n$i"], $offset2["n$i"], mosaicImgName["n$i"], $discImgName["n$i"]) = $line; Description: We read in data until the end-of-file. The data is fetched, via fscanf into the string variable $line. $line is then broken up into its component variables. We read in data until the end-of-file. The data is fetched, via fscanf into the string variable $line. $line is then broken up into its component variables.

readConsistencyFile.php – continued // trim removes a trailing comma from each string variable // trim removes a trailing comma from each string variable $wfo2["n$i"]=trim($wfo2_row,","); $wfo2["n$i"]=trim($wfo2_row,","); $day["n$i"]=trim($day_row,","); $day["n$i"]=trim($day_row,","); $element["n$i"]=trim($element_row,","); $element["n$i"]=trim($element_row,","); $validTime["n$i"]=$ymd_row. " ". trim($hr_row,","); $validTime["n$i"]=$ymd_row. " ". trim($hr_row,","); if ($avgDiff["n$i"] > $thresh["n$i"]) if ($avgDiff["n$i"] > $thresh["n$i"]) $facefile["n$i"]="../staticimages/frown.gif"; $facefile["n$i"]="../staticimages/frown.gif"; else else $facefile["n$i"]="../staticimages/smile.gif"; $facefile["n$i"]="../staticimages/smile.gif"; } else{ else{ } $i++; $i++; } if ($i == 0){ // didn't read any data, return an error code if ($i == 0){ // didn't read any data, return an error code return -10; return -10; } fclose($fp); fclose($fp); return 0; return 0;}?> Description: The associative arrays are then loaded. The associative arrays are then loaded. After all of the data is read, the file is closed and we return to calling routine After all of the data is read, the file is closed and we return to calling routine

Function: HourlyTables.php <?php if($spec[0] != "K" && substr($spec,0,2) != "PA"){ if($spec[0] != "K" && substr($spec,0,2) != "PA"){?> &wfo= &spec= "> &wfo= &spec= "> <?php } if ($spec[0] == "K" || substr($spec,0,2) == "PA" || $spec[0] == "D"){ if ($spec[0] == "K" || substr($spec,0,2) == "PA" || $spec[0] == "D"){?> &wfo= &spec= "> &wfo= &spec= "> Description: This.php file is included by display_consistency.php. It contains the sortable table. The sortable table has html forms for each column heading that sets the $_POST[“column heading”] variable. Later in the code, the value of each of these variables is checked, and if one is not NULL, the table is sorted by that column. This.php file is included by display_consistency.php. It contains the sortable table. The sortable table has html forms for each column heading that sets the $_POST[“column heading”] variable. Later in the code, the value of each of these variables is checked, and if one is not NULL, the table is sorted by that column. First, we set up the basic HTML table. First, we set up the basic HTML table. Then we create the forms for each column heading. It appears simply as submit button with the column name inside it. Then we create the forms for each column heading. It appears simply as submit button with the column name inside it. The if statements are used to selectively output the right headings, since they differ depending upon $spec. The if statements are used to selectively output the right headings, since they differ depending upon $spec.

HourlyTables.php – continued <?php } if($spec[0] != "D"){ if($spec[0] != "D"){?> &wfo= &spec= "> &wfo= &spec= "> <?php } if ($spec[0] == "K" || substr($spec,0,2) == "PA") if ($spec[0] == "K" || substr($spec,0,2) == "PA") $thisType="wfo2"; $thisType="wfo2"; else if($spec[0] == "D") else if($spec[0] == "D") $thisType="day"; $thisType="day"; else else $thisType="element"; $thisType="element"; // The following html block defines the table headlines // The following html block defines the table headlines // as submit buttons on an HTML form. Clicking the // as submit buttons on an HTML form. Clicking the // submit button sorts the data using that column. // submit button sorts the data using that column. Description: This is the same type of operation as the previous slide. Notice that even outside of the PHP block, the following HTML code is still contained in the PHP if construct. This is the same type of operation as the previous slide. Notice that even outside of the PHP block, the following HTML code is still contained in the PHP if construct.

HourlyTables.php - continued &wfo= &spec= "> &wfo= &spec= "> &wfo= &spec= "> &wfo= &spec= "> &wfo= &spec= "> &wfo= &spec= "> &wfo= &spec= "> &wfo= &spec= "> Description: This is the remainder of the column headings/forms. These columns are always present. A few have omitted… This is the remainder of the column headings/forms. These columns are always present. A few have omitted…

HourlyTables.php - continued <?php // Main array that will be sorted // Main array that will be sorted $mainArray = array(); $mainArray = array(); if ($_POST["OrderWFO"]){ if ($_POST["OrderWFO"]){ // Now we use the _POST array to access the // post data sent to this page // Notice that the associative index of the // Notice that the associative index of the // _POST array is the "name" of the HTML form // input statement // array_multisort sorts using two arrays: // array_multisort sorts using two arrays: // wfo and validTime array_multisort($wfo2,$validTime, array_multisort($wfo2,$validTime, SORT_REGULAR); SORT_REGULAR); $mainArray=$wfo2; $mainArray=$wfo2; } else if ($_POST["OrderElement"]){ else if ($_POST["OrderElement"]){ // here we just sort using one asociative array // here we just sort using one asociative array // (meaning each element is refernced by a unique // (meaning each element is refernced by a unique // string rather than a number) // string rather than a number) asort($element,SORT_REGULAR); asort($element,SORT_REGULAR); $mainArray=$element; $mainArray=$element; }else{ asort($facefile,SORT_REGULAR); asort($facefile,SORT_REGULAR); $mainArray=$facefile; $mainArray=$facefile; } Description: If the $_POST[“”] variable for any of the columns is not NULL, the main_array is set to that columns array. If the $_POST[“”] variable for any of the columns is not NULL, the main_array is set to that columns array. The main array is later sorted, re-arranging the values in the array, but also re- arranging the associative indexes of all of the arrays. The main array is later sorted, re-arranging the values in the array, but also re- arranging the associative indexes of all of the arrays. Once again, each column heading is tested for, but for simplicity, some are omitted. Once again, each column heading is tested for, but for simplicity, some are omitted.

HourlyTables.php – cont $count=0; $count=0; // By having all of these arrays with the same // By having all of these arrays with the same // index names, we can keep all of the corresponding // index names, we can keep all of the corresponding // arrays together even after sorting any one of them. // arrays together even after sorting any one of them. foreach ($mainArray as $key => $val){ foreach ($mainArray as $key => $val){ // Select which rows to print out. // Select which rows to print out. if ($thisType == "wfo2"){ if ($thisType == "wfo2"){ $comp=$wfo2[$key]; $comp=$wfo2[$key]; if ($comp == $spec){ if ($comp == $spec){ echo " <span class=\"black\"> ". $element[$key] class=\"black\"> ". $element[$key]." {$day[$key]} ";." {$day[$key]} "; echo " {$validTime[$key]} " echo " {$validTime[$key]} ". " <img src=\"". $facefile[$key]. "\" width=\"18\" height=\"18\"> ". "\" width=\"18\" height=\"18\"> ". " {$numPts[$key]} ". " {$numPts[$key]} ". "{$thresh[$key]} {$elevDiff[$key]} ". "{$thresh[$key]} {$elevDiff[$key]} ". "{$avgDiff[$key]} {$bias[$key]}. "{$avgDiff[$key]} {$bias[$key]} {$offset1[$key]} " {$offset1[$key]} ". " {$offset2[$key]} \n";. " {$offset2[$key]} \n"; } } Description: We then loop through the main_array. The foreach construct is a useful way to do that. We then loop through the main_array. The foreach construct is a useful way to do that. Once again, we need to selectively print out the data, hence the if ($thisType… statements. Once again, we need to selectively print out the data, hence the if ($thisType… statements. We then output the data in HTML format. We then output the data in HTML format.

HourlyTables.php – continued else{ else{ $comp=$day[$key]; $comp=$day[$key]; if ($comp == $spec){ if ($comp == $spec){ echo " ". $wfo2[$key] echo " ". $wfo2[$key]. " {$element[$key]} "; echo " {$validTime[$key]} “. " {$validTime[$key]} “. " <img src=\"". $facefile[$key]. "\" width=\"18\" height=\"18\"> “. " {$numPts[$key]} ". "\" width=\"18\" height=\"18\"> “. " {$numPts[$key]} ". "{$thresh[$key]} {$elevDiff[$key]} ". "{$thresh[$key]} {$elevDiff[$key]} ". "{$avgDiff[$key]} {$bias[$key]} {$offset1[$key]} ". "{$avgDiff[$key]} {$bias[$key]} {$offset1[$key]} ". " {$offset2[$key]} \n";. " {$offset2[$key]} \n"; } } }?></table> Description: This outputs the data for the other options, one of which was left out in the slide. This outputs the data for the other options, one of which was left out in the slide.

PHP Resources PHP.net – PHP.net – –One stop shop for almost any PHP information. WebMonkey - WebMonkey –Contains more specific (and obscure) applications of PHP.