210 likes | 461 Views
CS50. Section: Pset7. Jordan Jozwiak. Announcements. Section was cancelled last week due to Hurricane Sandy! Make-up lecture was filmed on Friday Pre-proposals were due at noon today! Pset6 will be returned by Tuesday night Still looking for a final project partner?
E N D
CS50 Section: Pset7 Jordan Jozwiak
Announcements • Section was cancelled last week due to Hurricane Sandy! • Make-up lecture was filmed on Friday • Pre-proposals were due at noon today! • Pset6 will be returned by Tuesday night • Still looking for a final project partner? • Cs50.net/partners/form • Cs50.net/partners/spreadsheet • Don’t forget to add music to our coding playlist!
This Week • The internet … a whole new world • HTML • chmod • PHP • mySQL • Section of Questions
HTML • HyperText Markup Language • Used to format contents of web pages. • NOT a programming language <!DOCTYPE html> <html> <body> <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html>
HTML • ‘Tags’ enclose regions of page. • <html> • <body> • <h1> , <h2>, <h3>, <p>, <br/> • <image>, <table>, etc. • Tags may have attributes • Forms allow input of different types on a webpage, such as checkboxes, radio buttons, text boxes and submit buttons • Information from forms may be submitted and sent to another page for use (this is usually where PHP comes in)
CSS • CSS: Cascading Style Sheets • Allows for easier formatting of HTML • Specifically formats different types of elements • May be included in separate file or in-lined (what are the advantages and disadvantages of each approach?) body { background-color:#d0e4fe; } h1 { color:orange; text-align:center; }
chmod • Abbreviate from “change mode” • Command-line function for controlling ‘read’, ‘write’ and ‘execute’ permission to User, Group and World • Can use octal values directly, e.g.: • chmod 644 index.html • Sets permissions so only owner can read and write to the file; and everyone else can only read it • chmod 600 helpers.php • Only owner can read, write and execute
chmod • 644 for non-PHP files • 600 for PHP files • 711 for directories
PHP • PHP: PHP Hypertext Preprocessor • When accessed, dynamically generates a webpage which it then outputs to browser. • PHP code is executed by the server, not by the browser • PHP code enclosed in <?php ?> tags • All PHP variables are prefaced by a $. You do NOT declare variables with a type
PHP • Compile with clang, then run executable. • Each variable is declared with a type, and you cannot (without casting) mix and match data types, e.g.: int a = 3; char *s = "hello"; s = s + a; // won’t compiled • Doesn’t get compiled; whole program is (generally) interpreted line by line • Variables don’t have types, and you can do weird mixings of data types, e.g.: $a = 3; $s = "hello"; $s = $s . $a; // gives "hello 3"
PHP • Single quotes vs. Double quotes • ‘this is a string’ • “This is also a string!\n” • Printing output • echo “hello” • print “hello” • <?= “hello” ?>
foreach (array_expression as $value) statement foreach (array_expression as $key => $value) statement PHP – foreach! foreach(array_expression as $value) statement foreach(array_expression as $key => $value) statement $arr= array("one" => 1,"two" => 2,"three" => 3,"seventeen" => 17);foreach ($arras $key=> $value) { echo "$key:$value\n";} $arr= array(1, 2, 3, 4);foreach ($arras $value) {echo $value;}
MySQL • SQL – Structured Query Language • Database software which allows us to store a collection of data as ‘entries’ containing a set of distinct ‘fields’ containing values. • Databases contains tables, which contain rows, which contain fields.
MySQL Queries • INSERT • Insert a new entry. • DELETE • Remove an existing entry. • SELECT • Select one or more entries. • UPDATE • Update the fields of an existing entry.
MySQL WARNING: It is always important to ‘escape’ the contents of any string passed by the user which is to be included in a database query. "INSERT INTO students VALUE ('<user string');" What could possibly go wrong?
Coding time!!! • Use the Appliance • dynamic.php (~7 min) • unique.php(~28 min) • concentrations.php (~25min) • wgethttp://cdn.cs50.net/2012/fall/sections/9/section9/concentrations.txt • Functions to consider • is_readable(), file(), chop()
On your way out… • Remember that you can access section powerpoints and SOQ solutions at http://cloud.cs50.net/~jjozwiak/ • Check out some database examples from last year at • http://cloud.cs50.net/~jjozwiak/source_code/week8.zip • http://cloud.cs50.net/~jjozwiak/section/week8/index.html