section: pset7
DESCRIPTION
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? - PowerPoint PPT PresentationTRANSCRIPT
Section: Pset7Jordan Jozwiak
CS50
AnnouncementsSection was cancelled last week due to
Hurricane Sandy!Make-up lecture was filmed on FridayPre-proposals were due at noon today!Pset6 will be returned by Tuesday night Still looking for a final project partner?
Cs50.net/partners/formCs50.net/partners/spreadsheet
Don’t forget to add music to our coding playlist!
This WeekThe internet … a whole new world
HTMLchmodPHPmySQL
Section of Questions
HTMLHyperText Markup LanguageUsed 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 attributesForms allow input of different types on a webpage, such
as checkboxes, radio buttons, text boxes and submit buttonsInformation from forms may be submitted and sent to
another page for use (this is usually where PHP comes in)
CSSCSS: Cascading Style SheetsAllows for easier formatting of HTMLSpecifically formats different types of
elementsMay 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;
}
chmodAbbreviate 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
# Permission rwx
7 full 111
6 read and write 110
5 read and execute 101
4 read only 100
3 write and execute 011
2 write only 010
1 execute only 001
0 none 000
chmod644 for non-PHP files600 for PHP files711 for directories
PHPPHP: 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
C PHPCompiled InterpretedStrongly-typed
Loosely-typed
• 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"
PHPSingle quotes vs. Double quotes
‘this is a string’“This is also a string!\n”
Printing outputecho “hello”print “hello”<?= “hello” ?>
PHP – foreach!
foreach (array_expression as $value) statement
foreach (array_expression as $key => $value) statement
foreach (array_expression as $value) statement foreach (array_expression as $key => $value) statement
$arr = array(1, 2, 3, 4);foreach ($arr as $value) { echo $value;}
$arr = array( "one" => 1, "two" => 2, "three" => 3, "seventeen" => 17);
foreach ($arr as $key => $value) { echo "$key: $value\n";}
PHP Joke
MySQLSQL – 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 QueriesINSERT
Insert a new entry.DELETE
Remove an existing entry.SELECT
Select one or more entries.UPDATE
Update the fields of an existing entry.
MySQLWARNING: 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?
MySQL
Coding time!!!Use the Appliance
dynamic.php (~7 min)unique.php (~28 min)concentrations.php (~25min)
wget http://cdn.cs50.net/2012/fall/sections/9/section9/concentrations.txt
Functions to consideris_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/we
ek8.ziphttp
://cloud.cs50.net/~jjozwiak/section/week8/index.html