Class07 PHP: loops MIS 3501 Jeremy Shafer Department of MIS Fox School of Business Temple University
Course Overview We are here... MySQL To do: 2 Weeks We are here... HTML & CSS 2 Weeks PHP 3 Weeks PDO 2 weeks To do: Organize your code with MVC (1 week) Work with forms (1 week) Use cookies and sessions (1 week)
What 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
Conditional Statements
A little review…
A little review… (2)
A little review… (3)
Some more advanced conditional statements 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 …
Some more advanced conditional statements(2) 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!
This error message was created using a conditional statement. (Error trapping is just one use of conditional statements.)
(Doing the same thing over and over again) Loops (Doing the same thing over and over again)
A loop that stores the numbers 1 through 5 in a string
A more challenging question… Multiples of 3 and 5 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.Find the sum of all the multiples of 3 or 5 below 1000. Discuss How would we solve this problem? Can you write a solution using pseudo-code? https://projecteuler.net/problem=1
Let’s try it…