DIG 4530c Lecture 2: - PowerPoint PPT Presentation

1 / 54
About This Presentation
Title:

DIG 4530c Lecture 2:

Description:

Start slow, make sure you got it. Accelerate rapidly. Lose 25% of you. See (some of) you in office ... So-called 'Smart Quotes' don't work in PHP. You need DUMB ... – PowerPoint PPT presentation

Number of Views:49
Avg rating:3.0/5.0
Slides: 55
Provided by: Mosh4
Category:
Tags: 4530c | dig | lecture | make | quotation | wamp

less

Transcript and Presenter's Notes

Title: DIG 4530c Lecture 2:


1
Media E-Commerce I
DIG 4530c - Lecture 2 Rapid Introduction To
PHP Programming Michael Moshell University of
Central Florida
2
  • The Objectives
  • Acquire/refresh key programming ideas
  • Learn how to debug a small program

3
  • The Strategy
  • Start slow, make sure you got it

850
4
  • The Strategy
  • Start slow, make sure you got it
  • Accelerate rapidly
  • Lose 25 of you

850
900
5
  • The Strategy
  • Start slow, make sure you got it
  • Accelerate rapidly
  • Lose 25 of you
  • See (some of)
  • you in office

850
900
930
6
  • The Strategy
  • Start slow, make sure you got it
  • Accelerate rapidly
  • Lose 25 of you
  • See (some of)
  • you in office

Drop/ add
850
900
930
Wed
7
  • The Strategy
  • Start slow, make sure you got it
  • Accelerate rapidly
  • Lose 25 of you
  • See (some of)
  • you in office
  • Greet late arrivers

Drop/ add
?
850
900
930
Wed
8
Task List 1 Random victims
9
Concept (-1) "Hello World"
The first program you write in a new
language lt?php print "Hello world!" ?gt The
"Daisy" song ... HAL in 2001
www.hexus.net
10
Concept 0 PHP in HTML
PHP is an embedded language. It can exist INSIDE
an HTML document. lthtmlgt ltbodygt lt?php x43
?gt lth2gt Welcome to the lt?php print x
?gtrd Reunion!lt/h2gt lt/bodygt lt/htmlgt
11
Concept 1 Data types
Numbers - Integers 0, 2, 4, 8 - Floating point
2.45, -888.99 no real distinction in PHP
12
Concept 1 Data types
Numbers - Integers 0, 2, 4, 8 - Floating point
2.45, -888.99 no real distinction in
PHP Strings (of characters) -Joe Wilson -My
left foot -3, 47, 238, 222.44
13
Concept 1 Data types
Numbers - Integers 0, 2, 4, 8 - Floating point
2.45, -888.99 no real distinction in
PHP Strings (of characters) -Joe Wilson -My
left foot -3, 47, 238, 222.44 Boolean true,
false
14
Concept 1 Data types
PHP plays fast and loose with types. You can
mix and match them, and it Does the best it can
to figure out your Meaning. Examples coming
soon.
15
Concept 2 Variables (simple)
Think of a variable as a labelled box. x
Name of the Variable (always begins With )
Contents Can be number, String or Boolean.
The CONTENTS of all the variables in a
program Represent its STATE or MEMORY.
16
Concept 3 Assignments,Constants
Putting something into a variable x
Before the assignment
x 47
The computer executes this statement, or command.
x
47
After the assignment
17
Concept 3 Assignments,Constants
Putting something into a variable x
Before the assignment
x 47
The computer executes this statement, or command.
x
47
After the assignment
Thats a constant (something that doesnt change.)
18
Concept 3 Assignment
Putting something ELSE into a variable x
47
Before the assignment
x 321
The computer executes this statement, or command.
19
Concept 3 Assignment
Putting something ELSE into a variable x
47
Before the assignment
x 321
The computer executes this statement, or command.
x
321
After the assignment
The previous contents are entirely replaced.
20
Concept 4 Expressions
In an Assignment The Expression on the RIGHT is
computed and then it is put into the variable.
x 33 22
First compute 3322, yields 55 Then dump it into
x.
x
55
21
About Variable Names
Safest names are plus text-strings, like
price You can do a lot of other stuff in php,
like _this But dont do this it has VERY
confusing consequences.
22
Concept 4 Expressions
The is an EVIL TRICKY SYMBOL. It really
should be an arrow like ? Because it does NOT
mean equals! It means evaluate right, copy to
left. pronounce "is replaced by the value of..."
x 33 x
Before execution
After execution
x
x
55
?
23
Concept 4 Expressions
The is an EVIL TRICKY SYMBOL. It really
should be an arrow like ? Because it does NOT
mean equals! It means evaluate right, copy to
left.
x 33 x
Before execution
After execution
x
x
55
88
24
Concept 5 Hand Simulation
Acting out what the program will do. Your job
Answer question at bottom.
x 3 y 2x 7 z 4 x y
z Print x
x
3
y
z
What is printed?
25
Concept 5 Hand Simulation
Acting out what the program will do. Your job
Answer question at bottom.
x 3 y 2x 7 z 4 x y
z Print x
x
3
y
13
z
What is printed?
26
Concept 5 Hand Simulation
Acting out what the program will do. Your job
Answer question at bottom.
x 3 y 2x 7 z 4 x y
z Print x
x
3
y
13
z
4
What is printed?
27
Concept 5 Hand Simulation
Acting out what the program will do. Your job
Answer question at bottom.
x 3 y 2x 7 z 4 x y
z Print x
x
3
17
y
13
z
4
What is printed?
28
Concept 5 Hand Simulation
Acting out what the program will do. Your job
Answer question at bottom.
x 3 y 2x 7 z 4 x y
z Print x
x
3
17
y
13
z
4
What is printed? 17 is printed.
29
Practice Hand Simulation
Acting out what the program will do. Your job
Answer question at bottom.
x 2 y 3x -4 z 3-y y y
z Print y
x
y
z
What is printed?
30
Practice Hand Simulation
Acting out what the program will do. Your job
Answer question at bottom.
x 2 y 3x -4 z 3-y y y
z Print y
x
y
z
What is printed? 3 is printed.
31
Practice Hand Simulation
Acting out what the program will do. Your job
Answer question at bottom.
x 2 y 3x -4 z 3-y y y
z Print y
2
x
y
z
What is printed? 3 is printed.
32
Practice Hand Simulation
Acting out what the program will do. Your job
Answer question at bottom.
x 2 y 3x -4 z 3-y y y
z Print y
2
x
2
y
z
What is printed? 3 is printed.
33
Practice Hand Simulation
Acting out what the program will do. Your job
Answer question at bottom.
x 2 y 3x -4 z 3-y y y
z Print y
2
x
2
y
1
z
What is printed? 3 is printed.
34
Practice Hand Simulation
Acting out what the program will do. Your job
Answer question at bottom.
x 2 y 3x -4 z 3-y y y
z Print y
2
x
2
y
3
1
z
What is printed? 3 is printed.
35
Concept 6 Comments
Human-readable reminders in the code. Three ways
to make them this hides the rest of the
line // and so does this
36
Concept 6 Comments
Human-readable reminders in the code. Three ways
to make them this hides the rest of the
line // and so does this / this hides
everything until you do its opposite like this
/
37
Concept 7 Logical expressions and code blocks
cost43 limit100 // and then later in the
program if (keyltlimit) print This is a
legal expenditure! else print No!
38
Concept 7 Logical expressions and code blocks
cost43 limit100 // and then later in the
program if (keyltlimit) print This is a
legal expenditure! else print No!
Logical Expression (T/F)
39
Concept 7 Logical expressions and code blocks
cost43 limit100 // and then later in the
program if (keyltlimit) print This is a
legal expenditure! else print No!
Logical Expression (T/F)
Code block
40
Aside PHP cares about Case!
Cost Is not the same as cost
41
Concept 8 Loops
Computers are useless for doing things
ONCE. k1 While (klt100) print
k k2k What will this print?
42
Aside What will it LOOK like?
Remember the output goes to a browser. k1 Whil
e (klt100) print k k2k What will
this print? 248163264
43
Aside What will it LOOK like?
Remember the output goes to a browser. k1 Whil
e (klt100) print k.\n k2k What
will this print?
44
Aside What will it LOOK like?
Remember the output goes to a browser. k1 Whil
e (klt100) print k.\n k2k What
will this print? 2 4 8 16 32 64 BUT lets VIEW
SOURCE.
45
Aside What will it LOOK like?
To make it react as if to HTML k1 While
(klt100) print k.ltbr /gt k2k What
will this print?
46
Aside What will it LOOK like?
To make it react as if to HTML k1 While
(klt100) print k.ltbr /gt k2k What
will this print?
2 4 8 16 32 64
47
Aside What will it LOOK like?
To make it react as if to HTML k1 While
(klt100) print k.ltbr /gt k2k We
concatenate a NUMBER k and a STRING ltbr /gt ..
It becomes a string.
We dissect This thing. DOT (.) means string
Concatenation (stick em together)
48
PHP Errors
Lets sabotage the program. Omit the
semicolon n1 While (nlt100) print
n.\n n2n .. And see what
happens. Parse error syntax error, unexpected
T_VARIABLE in C\wamp\www\little.php on line 6
49
What will it LOOK like?
Lets try to make a nice table appear. Print
lttable border1gt n1 While (nlt100) print
lttrgtlttdgt.n.lt/tdgtlt/trgt n2n Print
lt/tablegt
50
A microsoft GOTCHA!
So-called Smart Quotes dont work in PHP. You
need DUMB QUOTES like " Print " lttable border1gt
" n1 While (nlt100) print " lttrgtlttdgt ".n.
" lt/tdgtlt/trgt " n2n Print " lt/tablegt "
51
PHP emitting HTML
Now we will use our loop to make a
table. n1 While (nlt100) print
n.\n n2n .. And see what
happens. Parse error syntax error, unexpected
T_VARIABLE in C\wamp\www\little.php on line 6
52
Practice emitting HTML
  • Make this table appear!
  • 2. Make this table appear.
  • 3. How about this one? ( appears whenever the
  • contents exceed 16. Use an IF inside a loop)
  • 4. For the advanced among you

53
For Wed or Fri Lab
  • If you have a laptop
  • get WAMP or MAMP
  • Install it
  • Optional Get a text/reference book on PHP/mySQL
  • Everybody write up Task List 1
  • Write the answers. Well use them
  • in next weeks lecture.

54
And now the Diagnostic Quiz
You are free to use any knowledge you gained
today ... But I realize that it may not have
baked into your brains yet ...
simpsonstrivia.com
Write a Comment
User Comments (0)
About PowerShow.com