Presentation is loading. Please wait.

Presentation is loading. Please wait.

PHP Conditions MIS 3501, Fall 2014 Jeremy Shafer Department of MIS Fox School of Business Temple University September 11, 2014.

Similar presentations


Presentation on theme: "PHP Conditions MIS 3501, Fall 2014 Jeremy Shafer Department of MIS Fox School of Business Temple University September 11, 2014."— Presentation transcript:

1 PHP Conditions MIS 3501, Fall 2014 Jeremy Shafer Department of MIS Fox School of Business Temple University September 11, 2014

2 1.A bit more information about HTML forms 2.Conditional statements in PHP 2 Two topics to cover today…

3 Create a “week3” folder under your web root, and a file called “loopdemo.php” inside it. Recreate any of one of the correct loops illustrated in the previous slides. Now edit and add additional echo statements to make a table, using the loop Finally, can you introduce a variable call $Max that will control how many times the loop iterates? So, if I set $Max = 100, I should get a table with 100 rows. 3 First … recall this exercise from last class

4 A little more about the tag See http://www.w3schools.com/tags/tag_form.asphttp://www.w3schools.com/tags/tag_form.asp Discuss the tag attributes: action (Where to go) method (how to send data) method can be either GET or POST For now we are using GET Create a page called formdemo.php that sets the value of $Max in loopdemo.php 4

5 A little more about the tag See the formdemo.php page provided to you in week3.zip Note the use of the method and action What change do you need to make in loopdemo.php so that $Max changes with user input? 5

6 Making Decisions Decision making or flow control is the process of determining the order in which statements execute in a program The special types of PHP statements used for making decisions are called decision-making statements or decision-making structures

7 if Statements Used to execute specific programming code if the evaluation of a conditional expression returns a value of TRUE The syntax for a simple if statement is: if (conditional expression) { statement ; }

8 if Statements (continued) Contains three parts: –the keyword if –a conditional expression enclosed within parentheses –the executable statements A command block is a group of statements contained within a set of braces Each command block must have an opening brace ( { ) and a closing brace ( } )

9 if Statements (continued) $ExampleVar = 5; if ($ExampleVar === 5) { echo " The condition evaluates to true. "; echo " The variable is equal to ". $ExampleVar. " "); echo(" Each of these lines will be printed. "); } echo " This statement always executes after the if statement. ";

10 if...else Statements An if statement that includes an else clause is called an if...else statement An else clause executes when the condition in an if...else statement evaluates to FALSE The syntax for an if...else statement is: if (conditional expression) { statement; } else { statement; }

11 if...else Statements (continued) An if statement can be constructed without the else clause The else clause can only be used with an if statement $Today = " Tuesday " ; if ($Today === " Monday " ) { echo " Today is Monday “ ; } else { echo " Today is not Monday “ ; }

12 Nested if and if...else Statements When one decision-making statement is contained within another decision-making statement, they are referred to as nested decision-making structures if ($SalesTotal >= 50) { if ($SalesTotal <= 100) { echo " The sales total is between 50 and 100, inclusive. " ; }

13 Conditional Statements - Exercise Open up login.php See this php block at the top of the page: <?php if (isset($_GET[‘theSubmitButton'])) { echo "hello!"; } ?> Try it out. How does the page behave? What is the action tag set to. Why? What is isset doing? 13


Download ppt "PHP Conditions MIS 3501, Fall 2014 Jeremy Shafer Department of MIS Fox School of Business Temple University September 11, 2014."

Similar presentations


Ads by Google