forked from b2much/gdi-intro-php-mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class2.html
558 lines (522 loc) · 22.1 KB
/
class2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
<!doctype html>
<html lang="en">
<head>
<title>Class 2 ~ PHP/MySQL ~ Girl Develop It</title>
<meta name="description" content="This is a modification of the official Girl Develop It PHP/MySQL curriculum, developed by Sylvia Richardson for the Raleigh/Durham chapter.
The course is meant to be taught in 4 two-hour sections. Each of the slides and practice files are customizable according to the needs of a given class or audience.">
<meta name="author" content="Girl Develop It">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<link rel="stylesheet" href="css/custom.css">
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/simple.css" id="theme">
<!-- For syntax highlighting -->
<!-- light editor<link rel="stylesheet" href="lib/css/light.css">-->
<!-- dark editor--><link rel="stylesheet" href="lib/css/dark.css">
<link rel="stylesheet" href="lib/css/zenburn.css">
<link rel="stylesheet" href="plugin/accessibility-helper/css/accessibility-helper.css">
<!-- If the query includes 'print-pdf', include the PDF print sheet -->
<script>
if( window.location.search.match( /print-pdf/gi ) ) {
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'css/print/pdf.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
}
</script>
<!-- If use the PDF print sheet so students can print slides-->
<link rel="stylesheet" href="css/print/pdf.css" type="text/css" media="print">
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<!-- Opening slide -->
<section>
<section>
<img src="img/circle-gdi-logo.png" alt="GDI Logo" class="noborder" style="max-height:400px;">
<h3>Intro to PHP and MySQL</h3>
<h4>Class 2</h4>
</section>
</section>
<!-- Welcome-->
<section id="welcome">
<section>
<h3>Welcome!</h3>
<div class = "left-align">
<p>Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.</p>
<p class ="green">Some "rules"</p>
<ul>
<li>We are here for you!</li>
<li>Every question is important.</li>
<li>Help each other.</li>
<li>Have fun.</li>
</ul>
</div>
</section>
<section>
<h3>Debugging your code</h3>
<p>Not seeing anything when you run your code? You may need to turn on error logging. Put this code at the top of your page.</p>
<pre><code class="php">// Report all PHP errors
error_reporting(-1);
</code></pre>
</section>
</section>
<!-- Review -->
<section id="review">
<section>
<h3>Let's Look Back</h3>
<img src="img/backwards-dance.jpg" alt="Woman looking backward as she dances"/>
<p><small>Photo credit: <a href="http://www.flickr.com/photos/zeepack/4398082292/" target="_blank">Deepak Bhatia</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></small></p>
</section>
<section>
<h3>Code Search</h3>
<p>In this code, spot the comments, variables, operator, function, argument, and return value.</p>
<pre><code class="php">function calculateTip($total) {
$tipPercent = 0.15; //Can be changed
return ($total * $tipPercent);
}
$billTotal = 10;
$billTip = calculateTip($billTotal);
$receipt = 'Meal: ' . $billTotal . ' Tip: ' . $billTip .
' Total: ' . ($billTotal + $billTip);
echo $receipt;
</code></pre>
</section>
</section>
<!-- Variable Scope -->
<section id="scope">
<section>
<h3>Variable Scope</h3>
<p>The scope of a variable is how long the computer will remember it.</p>
<img src="img/footprints.jpg" alt="Footprints being washed away"/>
<p><small>Photo credit: <a href="http://www.flickr.com/photos/heyvikram/187950111/" target="_blank">_vikram</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></small></p>
</section>
<section>
<h3>Global Scope</h3>
<p>A variable declared outside a function has a <span class="blue">global</span> scope and can only be accessed outside a function.</p>
<pre><code class="php">$awesomeGroup = 'Girl Develop It'; //Global scope
function whatIsAwesome() {
echo $awesomeGroup . ' is pretty awesome.';
}
whatIsAwesome();
</code></pre>
</section>
<section>
<h3>Local Scope</h3>
<p>A variable declared within a function has a <span class="blue">local</span> scope and can only be accessed within that function.</p>
<pre><code class="php">function whatIsAwesome() {
$awesomeGroup = 'Girl Develop It'; //Local scope
}
echo $awesomeGroup . ' is pretty awesome.';
</code></pre>
</section>
</section>
<!-- Boolean -->
<section id="boolean">
<section>
<h3>Boolean Variables</h3>
<img src="img/kitten-switch.jpg" alt="Kitten with light switch"/>
<p><small>Photo credit: <a href="http://www.flickr.com/photos/elycefeliz/5726163170/" target="_blank">elycefeliz</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></small></p>
</section>
<section>
<h3>Boolean Variables</h3>
<p>Boolean variables represent the logical values True and False</p>
<pre><code class="php">$catsAreBest = true;
$dogsRule = false;
</code></pre>
<p>If you try to use another variable as a boolean, PHP will guess. The number 0, the empty string '', and the string '0' are considered false, everything else reads as true.</p>
</section>
</section>
<!--If/Then-->
<section id="if-then">
<section>
<h3>Control Flow</h3>
<img src="img/fork-path.jpg" alt="Forked path"/>
<p><small>Photo credit: <a href="http://www.flickr.com/photos/dennism2/1504087870/" target="_blank">DennisM2</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></small></p>
</section>
<section>
<h3>The if statement</h3>
<p>Use if to tell PHP which lines of code to execute, based on a condition.</p>
<pre><code class="php">if (condition) {
// statements to execute
}
</code></pre>
<pre><code class="php">$bananas = 5
if ($bananas > 0) {
echo 'You have some bananas!';
}
</code></pre>
</section>
<section>
<h3>Comparison Operators</h3>
<table class="smalltext">
<thead>
<tr>
<th width="150px">Example</th>
<th width="250px">Name</th>
<th>Result</th>
</tr>
</thead>
<tbody>
<tr>
<td>$a == $b</td>
<td>Equal</td>
<td><strong><code>TRUE</code></strong> if $a is equal to $b (can be different types).</td>
</tr>
<tr>
<td>$a === $b</td>
<td>Identical</td>
<td><strong><code>TRUE</code></strong> if $a is equal to $b, and the the same type.</td>
</tr>
<tr>
<td>$a != $b</td>
<td>Not equal</td>
<td><strong><code>TRUE</code></strong> if $a is not equal to $b (can be different types).</td>
</tr>
<tr>
<td>$a !== $b</td>
<td>Not identical</td>
<td><strong><code>TRUE</code></strong> if $a is not equal to $b, or they are not the same type.</td>
</tr>
<tr>
<td>$a < $b</td>
<td>Less than</td>
<td><strong><code>TRUE</code></strong> if $a is strictly less than $b.</td>
</tr>
<tr>
<td>$a > $b</td>
<td>Greater than</td>
<td><strong><code>TRUE</code></strong> if $a is strictly greater than $b.</td>
</tr>
<tr>
<td>$a <= $b</td>
<td>Less than or equal to </td>
<td><strong><code>TRUE</code></strong> if $a is less than or equal to $b.</td>
</tr>
<tr>
<td>$a >= $b</td>
<td>Greater than or equal to </td>
<td><strong><code>TRUE</code></strong> if $a is greater than or equal to $b.</td>
</tr>
</tbody>
</table>
</section>
<section>
<h3>Watch out!</h3>
<p>Don't mix up = and ==</p>
<img src="img/caution.jpg" alt="Caution Tape"/>
<p><small>Photo credit: <a href="http://www.flickr.com/photos/pictureperfectpose/76138988/" target="_blank">Eugene Zemlyanskiy</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></small></p>
</section>
<section>
<h3>Let's Develop It</h3>
<p>Make a variable called "temperature." Write some code that tells you to put on a coat if it is below 50 degrees.</p>
</section>
</section>
<!--If/else -->
<section id="if-else">
<section>
<h3>Even more control flow</h3>
<img src="img/toomanysigns.jpg" alt="Sign post with multiple signs"/>
<p><small>Photo credit: <a href="http://www.flickr.com/photos/thomashawk/2402598275/" target="_blank">Thomas Hawk</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></small></p>
</section>
<section>
<h3>The if/else statement</h3>
<p>Use else to provide an alternate set of instructions.</p>
<pre><code class="php">$age = 28;
if ($age >= 16) {
echo 'Yay, you can drive!';
} else {
echo 'Sorry, but you have ' . (16 - $age) .
' years until you can drive.';
}
</code></pre>
</section>
<section>
<h3>The if/else if/else statement</h3>
<p>If you have multiple conditions, you can use else if.</p>
<pre><code class="php">$age = 20;
if ($age >= 35) {
echo 'You can vote AND hold any place in government';
} else if ($age >= 30) {
echo 'You can vote AND run for the Senate';
} else if ($age >= 18) {
echo 'You can vote';
} else {
echo 'You can\'t vote, but you can still
write your representatives.';
}
</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<p>Modify your "wear a coat" code for these conditions:</p>
<ol>
<li>If it is less than 50 degrees, wear a coat.</li>
<li>If it is less than 30 degrees, wear a coat and a hat.</li>
<li>If it is less than 0 degrees, stay inside.</li>
<li>Otherwise, wear whatever you want.</li>
</ol>
</section>
<section>
<h3>Logical Operators</h3>
<table>
<thead>
<tr>
<th width="200px">Example</th>
<th width="150px">Name</th>
<th>Result</th>
</tr>
</thead>
<tbody>
<tr>
<td>$a and $b</td>
<td>And</td>
<td><strong><code>TRUE</code></strong> if both $a and $b are <strong><code>TRUE</code></strong>.</td>
</tr>
<tr>
<td>$a && $b</td>
<td>And</td>
<td><strong><code>TRUE</code></strong> if both $a and $b are <strong><code>TRUE</code></strong>.</td>
</tr>
<tr>
<td>$a or $b</td>
<td>Or</td>
<td><strong><code>TRUE</code></strong> if either $a or $b is <strong><code>TRUE</code></strong>.</td>
</tr>
<tr>
<td>$a || $b</td>
<td>Or</td>
<td><strong><code>TRUE</code></strong> if either $a or $b is <strong><code>TRUE</code></strong>.</td>
</tr>
<tr>
<td>$a xor $b</td>
<td>Xor</td>
<td><strong><code>TRUE</code></strong> if either $a or $b is <strong><code>TRUE</code></strong>, but not both.</td>
</tr>
<tr>
<td>! $a</td>
<td>Not</td>
<td><strong><code>TRUE</code></strong> if $a is not <strong><code>TRUE</code></strong>.</td>
</tr>
</tbody>
</table>
</section>
<section>
<h3>Using logical operators</h3>
<p>You can use these operators to combine conditions.</p>
<pre><code class="php">$bananas = 5;
if ($bananas >=2 && $bananas <7) {
echo 'You have a reasonable number of bananas';
} else {
echo 'Check your banana supply';
}
</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<p>Add a logical operator to your what to wear program.</p>
</section>
</section>
<!-- Loops -->
<section id="loops">
<section>
<h3>Loops</h3>
<img src="img/kitten-circle.jpg" alt="Kitten in ball"/>
<p><small>Photo credit: <a href="http://www.flickr.com/photos/courtneypix/9185593/" target="_blank">Courtney Patubo Kranzke</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></small></p>
</section>
<section>
<h3>While loops</h3>
<p>While will repeat the same code over and over as long as some condition is met.</p>
<pre><code class="php">$bottlesOfBeer = 99;
while ($bottlesOfBeer >= 1) {
echo $bottlesOfBeer . ' bottles of beer on the wall <br />';
$bottlesOfBeer = $bottlesOfBeer - 9;
}
</code></pre>
</section>
<section>
<h3>Infinite Loops</h3>
<p>Make sure something changes in the loop, or your loop will go on forever...</p>
<img src="img/infinite-loop.jpg" alt="Spiral that goes on toward infinity"/>
<p><small>Photo credit: <a href="http://www.flickr.com/photos/samueljohn/5348462863/" target="_blank">Samuel John</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></small></p>
</section>
<section>
<h3>For loops</h3>
<p>For loops are very similar, but you declare a counter in the statement.</p>
<pre><code class="php">
//will count 1 to 10
for ($i = 1; $i <= 10; $i++) {
echo $i;
}
</code></pre>
</section>
<section>
<h3>Loops and logic</h3>
<p>You can add other statements or logical operators inside the loops.</p>
<pre><code class="php">//Count from 1 to 50.
for ($i = 1; $i <= 50; $i++) {
echo $i;
//Says 'Buzz' after multiples of three
if ($i%3 == 0) {
echo ' Buzz';
}
//Says 'Bang' after multiples of five
if ($i%5 == 0) {
echo ' Bang';
}
echo '<br />'; //line break
}
</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<p>Write a loop that gives you the 9's times table,<br /> from 9 x 1 = 9 to 9 x 12 = 108.</p>
<p>Finish early? Try using a loop inside a loop to write all the times tables, from 1 to 12.</p>
</section>
</section>
<!-- Arrays -->
<section id="arrays">
<section>
<h3>Arrays</h3>
<img src="img/kitten-group.jpg" alt="Group of kittens"/>
<p><small>Photo credit: <a href="http://www.flickr.com/photos/pasotraspaso/4444291348/" target="_blank">Jesus Solana</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></small></p>
</section>
<section>
<h3>Arrays</h3>
<p>Arrays are lists of values associated with a key. The key needs to be an integer or a string, the value can be any type.</p>
<pre><code class="php">$kittenColors = array(
'Fluffy' => 'tabby',
'Midnight' => 'black',
'Admiral Snuggles' => 'white'
);
</code></pre>
</section>
<section>
<h3>Using arrays</h3>
<p>Once you have an array, you use a key to call a value.</p>
<pre><code class="php">$kittenColors = array(
'Fluffy' => 'tabby',
'Midnight' => 'black',
'Admiral Snuggles' => 'white'
);
echo $kittenColors['Midnight']; //prints 'black'
</code></pre>
</section>
<section>
<h3>Expanding arrays</h3>
<p>Arrays don't have a fixed length; you can add and take away items.</p>
<pre><code class="php">$kittenColors = array(
'Fluffy' => 'tabby',
'Midnight' => 'black',
'Admiral Snuggles' => 'white'
);
// This adds a new element to the array with key 'Monster'
$kittenColors['Monster'] = 'gray';
// This removes the element with the key 'Midnight'
unset($kittenColors['Midnight']);
</code></pre>
</section>
<section>
<h3>Arrays without keys</h3>
<p>If you don't specify a key, PHP will just automatically assign integers as keys, starting with zero.</p>
<pre><code class="php">$fruits = array("apple", "orange", "banana", "kiwi");
var_dump($fruits); //shows whole array
echo $fruits[1]; //will print orange
//You can add with no key as well
$fruits[] = 'mango';
var_dump($fruits);
</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<p>Create an array of your friends and their favorite foods. Echo a few values onto your screen.</p>
</section>
</section>
<!-- For Each Loops -->
<section id="foreach">
<section>
<h3>Foreach</h3>
<img src="img/holding-hands.jpg" alt="Couple holding hands"/>
<p><small>Photo credit: <a href="http://www.flickr.com/photos/mtsofan/8221708017/" target="_blank">John</a> <a href="http://creativecommons.org/licenses/by-nc/2.0/" target="_blank">cc</a></small></p>
</section>
<section>
<h3>Foreach loops</h3>
<p>Foreach is a special type of loop that works with arrays.</p>
<pre><code class="php">$numberList = array(1, 2, 3, 4, 5);
foreach ($numberList as $value) {
echo $value . ' times 2 equals ' . ($value*2) . '<br />';
}
</code></pre>
</section>
<section>
<h3>Arrays with keys</h3>
<p>You can also use the key values in your foreach loop.</p>
<pre><code class="php">$kittenColors = array(
'Fluffy' => 'tabby',
'Midnight' => 'black',
'Admiral Snuggles' => 'white',
);
foreach ($kittenColors as $name => $color) {
echo 'The kitten ' . $name . ' has ' . $color . ' fur.<br />';
}
</code></pre>
</section>
<section>
<h3>Let's Develop It</h3>
<p>Take your array of friends and write a foreach loop that echos "My friend NAME likes FOOD."</p>
</section>
</section>
<!-- Final slides-->
<section id="final">
<section>
<h3>You did it!</h3>
<img src="img/kitten-yay.jpg" alt="Happy cat"/>
<p><small>Photo credit: <a href="http://www.flickr.com/photos/laura-kali/7399310732/" target="_blank">OnceAndFutureLaura</a> <a href="http://creativecommons.org/licenses/by-sa/2.0/" target="_blank">cc</a></small></p>
</section>
<section>
<h3>Resources</h3>
<ul>
<li><a href="http://www.php.net/manual/en/" target="_blank">PHP Manual</a>, the official PHP documentation. Check the comments; they are useful.</li>
<li><a href="http://www.codecademy.com/tracks/php" target="_blank">Code Academy</a>, with interactive PHP lessons to help you review.</li>
</ul>
</section>
</section>
</div>
<footer>
<div class="copyright">
PHP/MySQL ~ Girl Develop It
<a rel="license" href="http://creativecommons.org/licenses/by-nc/3.0/deed.en_US"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-nc/3.0/80x15.png" /></a>
</div>
</footer>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
transition: 'slide', // none/fade/slide/convex/concave/zoom
// Optional reveal.js plugins
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, condition: function() { return !!document.querySelector( 'pre code' ); }, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true },
{ src: 'plugin/notes/notes.js', async: true },
{ src: 'plugin/accessibility-helper/js/accessibility-helper.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>