ITC 240: Web Application Programming SUBHASH PRAJAPATI 04/14/15.

Slides:



Advertisements
Similar presentations
Conditional Statements and Loops. Today’s Learning Goals … Learn about conditional statements and their structure Learn about loops and their structure.
Advertisements

Objectives Using functions to organize PHP code
1 PHP Statement Constructs Server Scripting. 5-2 Basic Statement All Statements end in a semicolon. Statements are delimited from the HTML code by enclosing.
PHP –Writing Reusable Code 10 March 2006 Adina Crainiceanu IT420: Database Management and Organization.
ITC 240: Web Application Programming
ITC 240: Web Application Programming SUBHASH PRAJAPATI 04/09/15.
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
CSCI 116 Decisions & Validation. Overview Constants Boolean conditions Decision logic Form validation 2.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 4- 1.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, © Copyright 2010, All Rights Reserved 1.
Chapter 4 Making Decisions
IS 1181 IS 118 Introduction to Development Tools VB Chapter 03.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Control Structures, Operators, and Functions.
Web forms in PHP Forms Recap  Way of allowing user interaction  Allows users to input data that can then be processed by a program / stored in a back-end.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Form Handling.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Includes and Dates.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
PHP Controlling Program Flow Mohammed M. Hassoun 2012.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
CIS 375—Web App Dev II JavaScript II.
Selection Structures (if & switch statements) (CS1123)
1 Session 3: Flow Control & Functions iNET Academy Open Source Web Programming.
Monday, Jan 13, 2003Kate Gregory with material from Deitel and Deitel Week 2 Questions from Last Week Control Structures Functions Lab 1.
PHP - Basic Language Constructs CSCI 297 Scripting Languages - Day Two.
CONTROL STRUCTURE The if, elseif, and else & switch Statements 1.
Slide 3-1 CHAPTER 3 Conditional Statements Objectives To learn to use conditional test statements to compare numerical and string data values To learn.
MS3304: Week 6 Conditional statements. Overview The flow of control through a script Boolean Logic Conditional & logical operators Basic decision making.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
Chapter 2 Functions and Control Structures PHP Programming with MySQL 2 nd Edition.
1 Module 3 Conditional Statements. Objectives  Conditional test statements to compare numerical and string data values  Looping statements to repeat.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
# ACS 168 Structured Programming Using the Computer Chapter 2 Spring 2002 Prepared by Shirley White.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Making Decisions.
1 JavaScript
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
Microsoft® Excel Key and format dates and times. 1 Use Date & Time functions. 2 Use date and time arithmetic. 3 Use the IF function. 4 Create.
JavaScript, Fourth Edition
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
IT ELECTIVE 2.  Web server Can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that.
Chapter Making Decisions 4. Relational Operators 4.1.
© M. Gross, ETH Zürich, 2014 Informatik I für D-MAVT (FS 2014) Exercise 4 – Logical Operators & Branching.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 4 Making Decisions.
CHAPTER 8 PHP Advanced อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
SESSIONS 27/2/12 Lecture 8. ? Operator Similar to the if statement but returns a value derived from one of two expressions by a colon. Syntax: (expression)
BOOLEAN OPERATIONS AND CONDITIONALS CHAPTER 20 1.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
XP Tutorial 3 New Perspectives on JavaScript, Comprehensive1 Working with Arrays, Loops, and Conditional Statements Creating a Monthly Calendar.
USING CONDITIONAL CODE AMIR KHANZADA. Conditional Statement  Conditional statements are the set of commands used to perform different actions based on.
Copyright © 2003 Pearson Education, Inc. Slide 3-1 The Web Wizard’s Guide to PHP by David A. Lash.
JavaScript JavaScript ( Condition and Loops ). Conditional Statements If Statement If...else Statement if (condition) { code to be executed if condition.
Unit – 3 Control structures. Condition Statements 1.If.…..else :- Has someone ever told you, "if you work hard, then you will succeed"? And what happens.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
>> Fundamental Concepts in PHP
CHAPTER 4 DECISIONS & LOOPS
Chapter 6: Conditional Statements and Loops
JavaScript: Control Statements.
More Selections BIS1523 – Lecture 9.
PHP.
Basics.
Introduction to Computer Science
BIT116: Scripting Lecture 6 Part 1
Presentation transcript:

ITC 240: Web Application Programming SUBHASH PRAJAPATI 04/14/15

Review Variable Types, Typecasting Constant Function Types Variable Scope

Today Functions: Passing by value, Passing by reference Conditionals Class Excercises

Passing by Value The default parameter will be passing by value. See following example: <?php function incrementTheVariable($var){ $var++; return $var; } $a=5; $b = incrementTheVariable($a); echo $a; echo $b; ?>

Passing by reference We can pass a variable by reference to a function so the function can modify the variable (both the variable point to the same content) <?php function incrementTheVariable(&$var){ $var++; } $a=5; incrementTheVariable($a); echo $a; ?>

Class Discussion o What are the advantages of using functions? o Should we echo inside a function? Why or why not?

Comparison Operations OperatorMeaning $a == $bEqual $a === $bIdentical (both value and type are equal) $a != $bNot Equal $a !== $bType and value are not equal $a < $bLess than $a <= $bLess than or equal to $a > $bGreat than $a >= $bGreater than or equal to

Logical Operators OperatorMeaning OR, ||OR AND, &&And XORReturns true if either is true. Returns false if both are true !negation

Conditionals Executing different code on given different circumstances Code branching/ Code separation

if statement

if(TEST CONDITION) { //code that occurs if condition proves true } Eg- $salary = 50000; echo "My salary is $". $salary. " "; if($s > 40000) { echo "I'm Happy!"; } // Now change the value to and see what happens

If/else statement

Eg- $salary = 50000; echo "My salary is $". $salary. " "; if($salary > 40000) { echo "I'm Happy!"; } else { echo “Life is not beautiful”; }

Class Exercise 3.1 Write a program to determine the large number in between two numbers. Write a program to determine a number is odd or even.

If, elseif statement (chain)

elseif statement $salary = 50000; echo "My salary is $". $salary. " "; If ($salary > 40000) { echo "I'm Happy!"; } else if ($salary > 30000) { echo “Life is still ok”; } else { echo “I don’t know what to say”; }

Nested statements if ($x < $y) { STATEMENTS_A } else { if ($x > $y) { STATEMENTS_B } else { STATEMENTS_C }

Class Exercise 3.2 o Write a program to display the office is open or closed depending on time the user visits the website. Office Hours: Mon-Fri 8:00 AM - 5:00 PM, Sat: 10:00 AM – 2:00 PM Hint: use php date() function to get the current hour/day date (‘G’) gives 24-hour format of an hour without leading zeros. date (‘l’) gives Monday through Saturday

Ternary Operator (condition) ? Value_if_true : Value_if_false <?php $opening_time = ( $day == “Sunday”) ? 12 : 9; // above code is equivalent to : if ($day == “Sunday”) $opening_time = 12; else $opening_time = 9; ?>

switch select one of many blocks of code to be executed. switch (n) { case label1: code to be executed if n=label1; break; case label2: code to be executed if n=label2; break; case label3: code to be executed if n=label3; break;... default: code to be executed if n is different from all labels; }

Class Exercise 3.3 o Write a program to greet the user with “Good Morning”, “Good Afternoon” or “Good Evening” depending on the time the user visits the website. Write this program utilizing switch statement.

Class Discussion o What is different between =, ==, ===?

Some PHP String functions o str_word_count ($string) – gives number of words in a string o str_replace ($search $replace, $subject) – replace certain word in a string o strlen ($string) – gives length of the string o strtolower ($string) – converts to lower case o strtoupper ($string) – converts to upper case o trim ($string) – removes white space in both the ends of the string Check PHP Manual for complete list of the functionsPHP Manual

Class Exercise 3.4 o Write a program to check whether or not the given word is ‘seattle’ (regardless of the case of the string the user passes and has a space at the end/front). For eg – the function will return true in any of the following ‘seattle’, ‘Seattle’, ‘seattle ’, ‘ sEaTtle ’

Code Organization with PHP o include and require include “file_path”; require “file_path”; on failure: require will produce a fatal error (E_COMPILE_ERROR) and stop the script include will only produce a warning (E_WARNING) and the script will continue o include_once and require_once similar to include/require with the only difference being that if the code from a file has already been included, it will not be included again.

Code Organization with PHP Welcome to my home page! Some text. Some more text.

Class Exercise 3.5 Create a webpage template in the format as shown in the picture. Create header, footer and nav templates to include in a webpage.