Download presentation
Presentation is loading. Please wait.
Published byEthan Richardson Modified over 9 years ago
1
ADVM420- Class #1 Web Design with PHP and MySQL Introduction to PHP © Copyright 2007 Grant Macewan College http://liftedu.wordpress.com Micah Slavens - micah@liftinteractive.com http://liftedu.wordpress.commicah@liftinteractive.com
2
Introduction Course Title Web design with PHP and MySQL Objectives Build dynamic, data-driven websites Gain the skills to learn and move forward Target Audience Some knowledge of HTML, databases, & programming is recommended Facilities Washrooms, cafeteria, parking Introductions and Interests What brought you to this course?
3
Target Environments Client Machine requirements: Text Editor FTP Server requirements: Can be Windows/Mac/Linux based Download & install appropriate software See reference Installing PHP & MySQL on http://liftedu.wordpress.com/resources/
4
Agenda Day 1: Web development concepts Tools of the trade HTML review Introduction to Scripting with PHP Include files HTML Forms & Validation Day 2: Listing data from MySQL Adding data to MySQL Creating Web applications Wrap-up
5
Web Development Concepts What is a Web Server? What is a Web Client? Static Web Pages HTML only Dynamic Web Pages HTML with Scripting language
6
Dynamic Web Pages Client Side AJAX – (Asynchronus Javascript & XML) DOM Scripting Flash Server Side Pre-processor that generates HTML Numerous scripting languages available PHP, Python, Ruby, ASP, ColdFusion, JSP, Perl, etc…
7
Server-Side Technology Advantages Ability to store data long term Code is protected Code logic is only visible through FTP (login protected) Potentially faster download times Code does not travel to client - public only sees results Disadvantages More load on server Server must support technology Less portability More knowledge required
8
Development Strategies Develop locally / upload to server Does not require permanent connection Can use your own resources (but you have to manage them) Does not interfere with existing site More control if things go wrong… Develop directly on a server via FTP You’ll be sure it works Easier in a team environement
9
Tools of the Trade We will be developing code on our server using a text Editor There are tools that will write blocks of code for you, but a text editor will give you a greater understanding of what you’re doing We won’t look at installing PHP or MySQL in class, but you’re welcome to give it a try on your own computer at home
10
XHTML Review Using Text Editor, create An index.html page 2 directories, called: /images /documents Heading Image (linked to in image directory) An unordered list Links to your 3 favorite sites An ordered list Steps to making a pb & j sandwich Save View
11
Web Standards W3C Standards make a better internet A usable standards based site will have a greater return No tables based designs! Semantic markup is beautiful Use only XHTML elements Make use of all the elements you can Clean markup and CSS will make a lighter, more usable application
12
Basic PHP Rules PHP script files end with the.php extension Scripting statements are enclosed in tags: <?PHP print (date("M d, Y")); ?> More simply: Or Try it! Rename your file index.php and include the lines shown above to show the server’s date
13
Data types in PHP PHP is four simple data types: Number (1, -5, 22.35, 1000000) String (“My dog”, “123 Any Street”) Boolean (true/false) Null Compound data types: Array$age[‘Bill’] = 15; $car[1] = “Ford”; Object
14
Variables and Statements Statements end with the semi-colon ; Capitalization is important! Variable names always prefixed with $ Comments begin with // $x = 15 / 9;//line1 comment $y = (65 * $x) % 15;//line2 comment
15
PHP Operators Math operators: + - * / %(Remainder) String operator:.(Concatenation) Comparison operators && AND ||OR !NOT
16
Program Output As we have seen, all output to the browser window is done using the print() or echo() functions (you can include html): <?PHP $x = 15 / 9; //comment $y = (65 * $x) % 15; print(“ The answer is: $y ”); ?>
17
Self-test: Simple Statements Write a program in PHP that calculates and displays a 10% discount on $199.99. Ensure all output has labels and make it appear on separate lines.
18
Program Blocks Program blocks are always contained in braces {…} if () {…} else {…} switch() {…} while() {…} do {…} while() for(;;) {…} function xyz() {…}
19
Decisions: if() {…} else {…} Syntax: if (condition) { true_statements; } else { false_statements; } Example: if ($x >= 10) { $x = $x * 0.9;//discount 10% } else { $x = $x * 0.95;//discount 5% }
20
Self-test: if() {…} else {…} Write a program in PHP that prints the words: “infant” if the variable $age is less than 1 “toddler” if the variable $age is less than 2 “child” if the variable $age is less than 13 “teen” if the variable $age is less than 18 “adult” otherwise
21
Decisions: switch () {…} Syntax: switch (value) { case N: statements; break; … default: statements; break; } Example: switch ($month) { case 1: print (“Jan”); break; case 2: print (“Feb”); break; default: print (“Err”); break; }
22
Self-test: switch () {…} Write a program in PHP that displays: “BMW200” if the variable $car is 200 “BMW203” if the variable $car is 203 “BMW205” if the variable $car is 205 “Error” otherwise
23
Loops: while() {…} Syntax: while (condition) { statements; } Example: What does this program do? $i = 0; $s = 0; while ($i < 7) { $s = $s + $i; $i = $i + 1; } print(“s= $s \n”);
24
Self-test: while() {…} Powers of Two Write a program that displays the series 2,4,8,16,32,64… until the number becomes greater than 5000.
25
Loops: do {…} while() Syntax: do { statements; } while (condition); Example: What does this program do? $i = 0; do { print(“i=“. $i. “ \n”); } while ($i != 0); do {…} while() always runs at least once.
26
Loops: for(;;) {…} Syntax: for (initialize; condition; increment) { statements; } Example: What does this program do? $f = 1; for ($i=1; $i<=5; $i++) { $f = $f * $i; } echo(“f=“. $f. “ \n”);
27
Self-test: for(;;) {…} Countdown Write a program that displays 10,9,8,…1 Blast Off! using a for loop.
28
function xyz() {…} Example: function xyz($arg1,$arg2,$arg3) { $answer = ($arg1+$arg2) / $arg3; return ($answer); } //calling the function… $r = xyz(1,2,3); print($r);
29
Self-test: function xyz() {…} weekdayName() Write a function returns the name of the week depending on the argument passed, for example: If 0 is passed, print “Sunday” If 1 is passed, print “Monday” … If 6 is passed, print “Saturday” Call this function with each day of the week and display the return value.
30
Summary This Module summarizes most of PHP ’s main elements: Check out some code Read blogs and forums Practice and experiment
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.