PHP Constructs Advance Database Management Systems Lab no.3.

Slides:



Advertisements
Similar presentations
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Advertisements

Creating PHP Pages Chapter 7 PHP Decisions Making.
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 Functions and Control Structures. 2 Defining Functions Functions are groups of statements that you can execute as a single unit Function definitions.
ITC 240: Web Application Programming
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic PHP.
Chapter 4 Functions and Control Structures PHP Programming with MySQL.
Repetition Statements repeat block of code until a condition is satisfied also called loops Java supports 3 kinds of loops: while statement – repeats a.
Introduction to JavaScript for Python Programmers
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
Php. What is PHP? PHP is an acronym for "PHP Hypertext Preprocessor" PHP is a widely-used, open source scripting language PHP scripts are executed on.
INTERNET APPLICATION DEVELOPMENT For More visit:
The foreach LooptMyn1 The foreach Loop The foreach loop gives an easy way to iterate over arrays. foreach works only on arrays, and will issue an error.
Decisions, Loops, and Arrays Achmad Arwan, S.Kom.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
4 1 Array and Hash Variables CGI/Perl Programming By Diane Zak.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
PHP. What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server.
Chapter 2 Functions and Control Structures PHP Programming with MySQL 2 nd Edition.
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.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Introduction to PHP.
JavaScript, Fourth Edition
PHP. PHP User Defined Functions Besides the built-in PHP functions, we can create our own functions. A function is a block of statements that can be used.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
CST336, Dr. Krzysztof Pietroszek Week 2: PHP. 1.Introduction to PHP 2.Embed PHP code into an HTML web page 3.Generate (output HTML) web page using PHP.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
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.
CGS 3066: Web Programming and Design Spring 2016 PHP.
 The real power of PHP comes from its functions; it has more than 1000 built-in functions.  PHP User Defined Functions  Besides the built-in PHP functions,
ITM 3521 ITM 352 Functions. ITM 3522 Functions  A function is a named block of code (i.e. within {}'s) that performs a specific set of statements  It.
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
A pache M ySQL P hp Robert Mudge Reference:
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
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 this.
PHP using MySQL Database for Web Development (part II)
Session 2 Basics of PHP.
>> Fundamental Concepts in PHP
Expressions and Control Flow in PHP
CHAPTER 5 SERVER SIDE SCRIPTING
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
JavaScript Syntax and Semantics
PHP Introduction.
Arrays, For loop While loop Do while loop
Chapter (3) - Looping Questions.
PHP.
Objectives In this chapter, you will:
MCS/BCS.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Basics (Cont...).
Decisions, Loops, and Arrays
PROGRAM FLOWCHART Iteration Statements.
PHP an introduction.
LOOPING STRUCTURE Chapter - 7 Padasalai
Presentation transcript:

PHP Constructs Advance Database Management Systems Lab no.3

LAB Outline PHP Loops PHP Functions Practice of PHP Array functions from previous Lab

PHP Loops While – loops through a block of code while a specified condition is true do...while – loops through a block of code once, and then repeats the loop as long as a specified condition is true For – loops through a block of code a specified number of times Foreach – loops through a block of code for each element in an array

While Loop Syntax while (condition) { code to be executed; } Example "; $i++; } ?>

While Loop Output of the example code The number is 1 The number is 2 The number is 3 The number is 4 The number is 5

Do While Loop Syntax do { code to be executed; } while (condition); Example "; } while ($i<=5); ?>

Do While Loop Output of the example code The number is 2 The number is 3 The number is 4 The number is 5 The number is 6

For Loop Used when number of times a code/script (to be executed) is known in advance Syntax for (init; condition; increment) { code to be executed; } Parameters : – init: Mostly used to set a counter (but can be any code to be executed once at the beginning of the loop)

For Loop – condition: Evaluated for each loop iteration. If it evaluates to TRUE, the loop continues. If it evaluates to FALSE, the loop ends. – increment: Mostly used to increment a counter (but can be any code to be executed at the end of the loop) Note: Each of the loop parameters can be empty, or have multiple expressions (separated by commas)

For Loop Example "; } ?> Output The number is 1 The number is 2 The number is 3 The number is 4 The number is 5

For Each Loop It is used to loop throuh arrays Syntax foreach ($array as $value) { code to be executed; } – For every loop iteration, the value of the current array element is assigned to $value and the array pointer is moved by one, so on the next loop iteration, you'll be looking at the next array value.

For Each Loop Example "; } ?> Output one two three

PHP Functions In PHP, there are more than 700 built-in functions. A function will be executed by function call. You may call a function from anywhere within a page. The function name can start with a letter or underscore (not a number)

PHP Functions An important use of function – To keep the browser from executing a script when the page loads, you can put your script into a function.

Creating a PHP Function Syntax function functionName() { code to be executed; } Example <?php function writeCourse() { echo “Advanced DBMS"; } echo “Course name is "; writeCourse(); ?>

Adding Parameters to Functions A parameter is just like a variable. They are specified after the function name, inside the parentheses A function can take one or more parameters.

Part of text Concatenation operator Example "; } echo “The best is "; writeChocoName(“Milk"); echo “Some people also like "; writeChocoName(“Dark"); echo “Few may like "; writeChocoName(“White"); ?>

Output The best is Milk Chocolate. Some people also like Dark Chocolate. Few may like White Chocolate.

Another Example (2 parameters) Output: The total score is 30

Function Returning Value <?php function add($x,$y) { $total=$x+$y; return $total; } echo " = ". add(1,16); ?> Output: = 17