Presentation is loading. Please wait.

Presentation is loading. Please wait.

Class07 PHP: loops and includes MIS 3501, Fall 2015 Brad Greenwood, PhD MBA Department of MIS Fox School of Business Temple University 9/15/2015.

Similar presentations


Presentation on theme: "Class07 PHP: loops and includes MIS 3501, Fall 2015 Brad Greenwood, PhD MBA Department of MIS Fox School of Business Temple University 9/15/2015."— Presentation transcript:

1 Class07 PHP: loops and includes MIS 3501, Fall 2015 Brad Greenwood, PhD MBA Department of MIS Fox School of Business Temple University 9/15/2015

2 © 2014, Mike Murach & Associates, Inc. 2 Housekeeping The exam has been rescheduled for the 24 th This gives an extra study day Tom will be scheduling a review session that week The exam is no joke I will be regrading the zero quizzes tomorrow Today is the last day to see me

3 What Have We Done © 2014, Mike Murach & Associates, Inc. Slide 3

4 MySQL Weeks 5 & 6 HTML & CSS Weeks 1 & 2 PHP Weeks 3 & 4 PDO Week 7 Course Overview 4 To do: Organize your code with MVC (week 8) Debug your code (week 9) Work with forms (week 10) Use arrays (week 11 & 12) Use sessions (week 13) We are here.

5 © 2014, Mike Murach & Associates, Inc. 5 What, structural, code have we learned so far? PHP code runs on the server PHP code is embedded in HTML PHP has a filter_input function that can be used to retrieve data from form posts Like any other programming language, PHP lets us store data in variables Our PHP code can take different actions based on conditional statements

6 © 2014, Mike Murach & Associates, Inc. 6 Objectives 1.Revisit conditional statements 2.Avoid redundant code with server-side includes 3.Avoid redundant code with loops

7 Conditional Statements © 2014, Mike Murach & Associates, Inc. 7

8 A little review… © 2014, Mike Murach & Associates, Inc. 8

9 A little review… (2) © 2014, Mike Murach & Associates, Inc. 9

10 A little review… (3) © 2014, Mike Murach & Associates, Inc. 10

11 © 2014, Mike Murach & Associates, Inc. 11 This error message was created using a conditional statement. Validation (that is error trapping) is just one use of conditional statements.

12 Some more advanced conditional statements © 2014, Mike Murach & Associates, Inc. 12 Lookie here! – Notice how we are considering three conditions in one statement. This condition reads: “if investment is empty OR investment is not numeric OR investment is less than or equal to 0 THEN …

13 Some more advanced conditional statements (2) © 2014, Mike Murach & Associates, Inc. 13 Notice also that if statements can be nested inside each other. Here, the “if years greater than one” condition is nested inside the else block of the first condition. Whew!

14 Server-Side Includes © 2014, Mike Murach & Associates, Inc. 14 (Some assembly required)

15 Server-Side Includes © 2014, Mike Murach & Associates, Inc. 15 Sometimes we have a portion of a web site (or web application) that we want to use over and over again. It could be something like a page header displaying a corporate logo, a copyright notice at the bottom of each page, or a piece of PHP code that was tricky to write once (so why not reuse it?)

16 Built-in functions used to assemble content from different files. © 2014, Mike Murach & Associates, Inc. 16 The exit and die functions do exactly the same thing: completely terminate further processing of the php page. The include and require functions are similar. They both inject content from another file into the current PHP page. The require function is the more strict of the two. If the file is not found, an warning is displayed and further processing of the page stops. Include let’s processing continue, but with a warning. These functions are just like their cousins above. They silently prevent the same content from being injected over and over again.

17 © 2014, Mike Murach & Associates, Inc. 17 Sometimes we choose to assemble our page based on one or more conditions. Moving up and down the hierarchy of our server’s file system

18 Loops © 2014, Mike Murach & Associates, Inc. 18 (Doing the same thing over and over again)

19 © 2014, Mike Murach & Associates, Inc. 19 A loop that stores the numbers 1 through 5 in a string This is the same as: $counter = $counter + 1;

20 The Future Value Calculator uses a loop © 2014, Mike Murach & Associates, Inc. 20

21 © 2014, Mike Murach & Associates, Inc. 21 How was this number calculated? ∑f(x i ) where f(x) = x + x*i

22 © 2014, Mike Murach & Associates, Inc. 22

23 © 2014, Mike Murach & Associates, Inc. 23

24 © 2014, Mike Murach & Associates, Inc. 24


Download ppt "Class07 PHP: loops and includes MIS 3501, Fall 2015 Brad Greenwood, PhD MBA Department of MIS Fox School of Business Temple University 9/15/2015."

Similar presentations


Ads by Google