Presentation is loading. Please wait.

Presentation is loading. Please wait.

PHP: Basics FdSc Module 109 Server side scripting and Database design

Similar presentations


Presentation on theme: "PHP: Basics FdSc Module 109 Server side scripting and Database design"— Presentation transcript:

1 PHP: Basics FdSc Module 109 Server side scripting and Database design
2011

2 Variables PHP is loosely typed – data types are automatically assigned
Examples Integer: 72 Double: 7.22 String: “Seven point two two” Boolean: True/False Array: Key [0], Value “Low”

3 Example <html> <head> <title>A PHP script including HTML</title> </head> <body> <b> <?php $message = "My age is "; $age = 25; print($message); print($age); ?> </b> </body> </html>

4 Concatenation operator
Concatenation appends operands together Represented by a single period (.) A operand is a variable, object or value <?php $message = "My age is "; $age = 25; print($message . $age . " years old"); ?>

5 Other Operators Arithmetic operators perform arithmetic operations on two or more operands An expression is a mathematical operation Operator Operation + Add - Subtract / Divide * Multiply % Modulus (remainder of x/y)

6 Expressions <?php $age = 25; print(" My age is $age years old"); echo "</br>"; print(" My age in days is " . ($age * 365) . " days old"); print(" My age in months is " . ($age * 12) . " months old"); ?>

7 Incrementing & decrementing
X = X + 1; X++; Decrementing X = X – 1 X--;

8 Loops Loops repeat sections of code either: Types of loops
A set number of times Until a condition is met Types of loops For … next loop Do … while loop Do … until loop

9 For .... next <?php for ($counter = 0; $counter < 10; $counter++) { print(" $counter times 2 is " . ($counter * 2)); print("<br>"); } ?>

10 Do .... While (runs at least once)
<?php $counter=0; while ($counter <10) { print(" $counter times 2 is " . ($counter * 2)); print("<br>"); $counter++; } ?>

11 Selection Controlling program flow is essential Types of selection:
If … else if … else switch

12 if .. else if ... if <?php $age = 15; if ($age >= 65) { print("You qualify for a state pension"); } else if ($age >= 35) { print("You ought to be saving for a pension"); } else print("Spend, spend, spend!"); ?>

13 Task Write a script that will deliver a grade from a given mark
Create a form to submit the mark for grading Mark Grade 70 or better A 60-69 B 50-59 C 40-49 D 30-39 Fail with retake 1-29 Fail no retake Ungraded


Download ppt "PHP: Basics FdSc Module 109 Server side scripting and Database design"

Similar presentations


Ads by Google