1 / 21

Section: Pset7

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?

gudrun
Download Presentation

Section: Pset7

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS50 Section: Pset7 Jordan Jozwiak

  2. 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!

  3. This Week • The internet … a whole new world • HTML • chmod • PHP • mySQL • Section of Questions

  4. 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>

  5. 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)

  6. 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; }

  7. 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

  8. chmod

  9. chmod • 644 for non-PHP files • 600 for PHP files • 711 for directories

  10. 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

  11. 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"

  12. PHP • Single quotes vs. Double quotes • ‘this is a string’ • “This is also a string!\n” • Printing output • echo “hello” • print “hello” • <?= “hello” ?>

  13. 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;}

  14. PHP Joke

  15. 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.

  16. 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.

  17. 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?

  18. MySQL

  19. 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()

  20. 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

More Related