AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Communication Technology

Term 1 review and your own mini-project

Week 15 · Term 1 review (Units 1–3) and your own mini-project · 3 lessons
2

Review: databases and PHP

ICT Secondary 2 Term 1, Review: pp. 7–113
GoalReview HTML, PHP code and forms: predict output and spot invalid lines.
New words
predict output · reading code line by line and writing what it prints before running itdouble quotes · quotes in which PHP replaces a variable by its valuebreak · the word that leaves a switch after a matching casepost form · a form that sends its values inside the request, not in the address
Explanation

Now Unit 3. Read the code slowly and write the answer before looking at it. In double quotes PHP puts the value of a variable into the text, and in single quotes it prints the characters as they are. An if with elseif and else tries the conditions from the top and runs only the first one that is true. A switch jumps to the matching case and then keeps running the next cases until it meets break; the word default runs when nothing matched. The classic mistakes are: a missing semicolon, one = (put a value) where == (compare) was meant, a forgotten $ before a variable name, and a closing tag that was never opened. For a form, choose post to send data that will be saved, such as a new term or a file, and get for a request that only looks something up. An html page uses lowercase tags and its picture needs an alt text.

Startbooks >= 10 ?yesnoprint goldbooks >= 3 ?yesnoprint silverprint newEnd
Worked examples
Php
1<?php
2$club = "Readers";
3echo "Welcome to $club", ' $club';
4?>
Output
Welcome to Readers $club
Predict the output. The first string is in double quotes, the second in single quotes. Two strings are printed one after the other.
Php
1<?php
2$books = 5;
3if ($books >= 10) {
4    echo "gold";
5} elseif ($books >= 3) {
6    echo "silver";
7} else {
8    echo "new";
9}
10?>
Output
silver
Predict the output with $books equal to 5. The first condition is false, the second is true, so only silver is printed.
Php
1<?php
2$d = 2;
3switch ($d) {
4    case 1: echo "A";
5    case 2: echo "B";
6    case 3: echo "C"; break;
7    default: echo "D";
8}
9?>
Output
BC
A switch without break after cases 1 and 2. The value is 2, so the case B runs, and the next case C runs too, until its break. Default is not reached.
Html
1<h1>Reading Club</h1>
2<p>Open on <b>Saturday</b>.</p>
3<a href="help.php">Help</a>
Read this HTML. It shows a large title, a line of text with the word Saturday in bold, and a link with the words Help that opens help.php. All the tags are lowercase and closed.
Class activity

Find the invalid line in each of these four PHP lines and write the correct line: (a) echo "Hello" (b) if ($a = 3) { echo "x"; } meant to compare (c) echo name; meant to print the variable $name (d) a closing </p> without an opening <p>. Then choose get or post for a search box and for the Add Term form, and give a reason.

Practice
1
What does echo '$x' print when $x is 5?
2
Which line is wrong: if ($a = 3)? Say why and give the fix.
3
Which form method for a new term with a picture?
4
In a switch with cases 1 and 2 and no break, the value is 1. What runs?