In Class Program: Today in History

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

Lecture 6/2/12. Forms and PHP The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input When dealing with HTML forms.
The Print Formatting Statement … named printf. 2 Introduction to printf statements print and println statements don’t allow us to easily format output.
Python and Web Programming
PHP and XML. Visual Studio/File/New/File I have switched to Visual Studio to make the XML – I think it provides an easier interface for creating an XML.
15. User Authentication, Form Validation, Paging. M. Udin Harun Al Rasyid, S.Kom, Ph.D
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
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.
Practical PHP IDIA Spring 2012 Bridget M. Blodgett.
Lecture 6 – Form processing (Part 1) SFDV3011 – Advanced Web Development 1.
Advanced Web 2012 Lecture 4 Sean Costain PHP Sean Costain 2012 What is PHP? PHP is a widely-used general-purpose scripting language that is especially.
JavaScript Lecture 6 Rachel A Ober
General Programming Introduction to Computing Science and Programming I.
Bill's Amazing Content Rotator jQuery Content Rotator.
PHP meets MySQL.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
1 Session 3: Flow Control & Functions iNET Academy Open Source Web Programming.
CSC Intro. to Computing Lecture 13: PALGO. Announcements Midterm is in one week  Time to start reviewing  We will do more review in class Tuesday.
If statements while loop for loop
11 1 Cookies CGI/Perl Programming By Diane Zak Objectives In this chapter, you will: Learn the difference between temporary and persistent cookies.
1 CS428 Web Engineering Lecture 20 Control Structures, Loops and Pointers File Uploading Function (PHP - III)
HTML FORMS GET/POST METHODS. HTML FORMS HTML Forms HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes,
Working with Files. Learning Objectives By the end of this lecture, you should be able to: – Examine a file that contains code with unfamiliar material,
PHP Form Introduction Getting User Information Text Input.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
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.
Files Tutor: You will need ….
 2001 Prentice Hall, Inc. All rights reserved. Chapter 7 - Introduction to Common Gateway Interface (CGI) Outline 7.1Introduction 7.2A Simple HTTP Transaction.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming –TextField Action Listeners, JEditorPane action listeners, HTML in a JEditorPane,
Functions.  Assignment #2 is now due on Wednesday, Nov 25 th  (No Quiz)  Go over the midterm  Backtrack and re-cover the question about tracing the.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
JavaScript Part 1 Introduction to scripting The ‘alert’ function.
Advanced HTML Tags:.
Introduction to Computing Science and Programming I
Loops BIS1523 – Lecture 10.
Introduction To Repetition The for loop
Arrays: Checkboxes and Textareas
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
Retrieving information from forms
Arrays and files BIS1523 – Lecture 15.
Intro to PHP & Variables
Cookies BIS1523 – Lecture 23.
Introduction to JavaScript
Introducing Forms.
HTML Forms and User Input
Google API Key.
Arrays & Functions Lesson xx
More Selections BIS1523 – Lecture 9.
A second look at JavaScript
Python I/O.
Functions BIS1523 – Lecture 17.
Conditions and Ifs BIS1523 – Lecture 8.
Passing Structures Lesson xx
Number and String Operations
In-Class Program: Sales System
Building Web Applications
In Class Programming BIS1523 – Lecture 11.
In Class Programming: Credit card payment
PHP.
Video list editor BIS1523 – Lecture 24.
Text Analyzer BIS1523 – Lecture 14.
Introduction to JavaScript
BIT116: Scripting Radio Buttons.
HTML Forms What are clients? What are servers?
Reading information from files
CS 11 – April 1 Review steps for lab #3
Retrieving information from forms
Presentation transcript:

In Class Program: Today in History BIS1523 – Lecture 19

Today In History Todays program will allow the user to enter in a day, and month. Then, it will search through a file containing a list of events and the dates they happened on, and print out the results of that search.

Program Design This program is designed as a single page PHP. Notice the POST action calls this same file We use option-lists to allow the user to make the selection, and then send them as month and day when the program posts.

Selecting Days The starting program only has the option for one day of selection. To expand that list, w need to have 31 different options That’s more typing that I’d like to do, so let’s automate it with some PHP and a loop.

Functions.php I’ve actually included that automation in a file called “functions.php”. And put it in a function called day_options() If we include that in our main program, we can have access to that function. Then, we do another PHP snippet to call the function. There is also a month_options function included.

Single Page Check Since we are using a single PHP page that calls itself, we need to make sure the month and day POST values were passed. If not, then we didn’t get here through the submit button, and we don’t need to do anything. We do that with an IF

The Trivia.Dat File The file ‘trivia.dat’ contains all our data on the events that happened throughout history. It is a ‘comma-separated-values’ file. Each line contains 4 pieces of information, separated by commas. The month, day, year, and an event that happened on that day.

Searching the File Searching the file is the normal algorithm we use. Read the file into an array Use a loop to go through each element of the array Inside the loop, use an if statement to see if we found what we are looking for. Let’s start with the basic “read the file, loop through it” loop. At each iteration of the loop, the variable $row will be a row from the file.

Splitting up $row Now, $row is a string that contains 4 pieces of information. We need to split it up to access each individual piece. To do that, we can use the “explode” function. We tell it to explode it based on the comma, and it will create an array of pieces, breaking it up using the comma as the marker for each piece. So Becomes: Fields 1 2 1801 3 Guiseppe Piazzi …..

Finding the Specific Date Now that we can access the day in $fields[1], and the month in $fields[2], we could print out everything that happened on January 1st by doing an if statement like: To search for the specific day the user entered, instead of using 1 and 1 for jan first, we need to use the day number and month number they selected. The day number is stored in the variable $day (we read it in from the $_POST)

Searching The month however was submitted using characters like “jan” and “feb”. The data in the file uses a number, so we need to convert it. There is a conversion function included in functions.php, that uses a switch to figure out which month is which.

Searching Using $day and our month function: All that is left is to add a little more HTML to round out the output.

Finished Program