<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://classes.engineering.wustl.edu/cse330/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Zach</id>
	<title>CSE330 Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://classes.engineering.wustl.edu/cse330/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Zach"/>
	<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Special:Contributions/Zach"/>
	<updated>2026-11-15T18:17:58Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.34.4</generator>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_2&amp;diff=2928</id>
		<title>Module 2</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_2&amp;diff=2928"/>
		<updated>2024-09-03T06:14:13Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Reading */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
Module 2 introduces you to Linux, a command-line environment, the Apache web server, and PHP.  You will create and configure your own cloud instance, install Apache and related software, and then form groups to make a simple file sharing site.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:1.3em; line-height:1.2em; color:blue;&amp;quot;&amp;gt;'''DO NOT WAIT UNTIL THE LAST MINUTE TO START ON THIS (or any) MODULE!'''  The most common reason students perform poorly in this class is procrastination.  You have been warned.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using the Wiki ==&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
Text enclosed by &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;&amp;lt;&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;&amp;gt;&amp;lt;/syntaxhighlight&amp;gt; should be replaced by content unique to you.&lt;br /&gt;
&lt;br /&gt;
'''Example'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo useradd -r -m -c &amp;quot;&amp;lt;My Full Name&amp;gt;&amp;quot; &amp;lt;usernameHere&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
becomes&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo useradd -r -m -c &amp;quot;Zach Cohn&amp;quot; zcohn&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Reading ==&lt;br /&gt;
&lt;br /&gt;
The following articles on the online class wiki textbook contain information that will help you complete the assignments.&lt;br /&gt;
&lt;br /&gt;
''To jump right into setting up your EC2 Instance, Begin with [[SSH]]''&lt;br /&gt;
&lt;br /&gt;
* [[Linux]]&lt;br /&gt;
* [[Bash]]&lt;br /&gt;
* [[Amazon Web Services]]&lt;br /&gt;
* [[SSH]]&lt;br /&gt;
* [[Apache]]&lt;br /&gt;
* [[PHP]]&lt;br /&gt;
* [[Workflow]]&lt;br /&gt;
* [[VS Code]]&lt;br /&gt;
* [[Web Application Security, Part 1]]&lt;br /&gt;
* [[FAQ - Mod 2]]&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;There are a lot of wiki pages that you need to read in order to complete the individual portion of Module 2.  The wiki pages contain an assortment of required steps, optional steps, and information.  To make things easier, we have highlighted the ''required steps'' with a red bar, like you see on the left of this message.  Do not skip anything marked with a red bar, or else you will not have a perfectly configured instance.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Learn About Linux ===&lt;br /&gt;
&lt;br /&gt;
Linux is an open-source operating system based on UNIX. Linux is highly versatile and is used in a wide range of applications.&lt;br /&gt;
&lt;br /&gt;
If you are not a Linux guru, read the Linux guide to get started: [[Linux]]&lt;br /&gt;
&lt;br /&gt;
=== Windows Users Only: Enable Windows Subsystem for Linux (WSL) or Install Cygwin ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You will need WSL or Cygwin in order to log into and configure your EC2 instance. Cygwin is already installed on the CEC machines. If you're using Windows 10, you can use WSL, which is an officially-supported way of accessing a Linux terminal on Windows. If not, you'll have to use Cygwin. Instructions for installing either on your personal machine are located in [[Workflow#Cygwin|the Workflow guide]].&lt;br /&gt;
&lt;br /&gt;
Mac OS X users should located the &amp;quot;Terminal&amp;quot; application, which is installed by default; you will need this in the coming steps.&lt;br /&gt;
&lt;br /&gt;
=== Create an AWS EC2 Instance ===&lt;br /&gt;
&lt;br /&gt;
Once you understand [[Linux]], you need to set up your Amazon EC2 Instance.  Use the AWS article to guide you through the process: [[Amazon Web Services]]&lt;br /&gt;
&lt;br /&gt;
=== Configure SSH ===&lt;br /&gt;
&lt;br /&gt;
Follow the instructions in [[SSH#SSH Configuration|the SSH guide]] to do the following:&lt;br /&gt;
&lt;br /&gt;
# Create your own SSH key pair&lt;br /&gt;
# Log in as the default user to your EC2 instance&lt;br /&gt;
# Create a new user&lt;br /&gt;
# Give the new user your SSH public key&lt;br /&gt;
&lt;br /&gt;
From now on, when you need to log into your EC2 instance as an administrator, just pop up a terminal and run:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ ssh &amp;lt;your-instance-username&amp;gt;@&amp;lt;ec2-xx-xx-xx-xx.compute-1.amazonaws.com&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To save from typing this command in every time you want to access your server, you can set an '''alias''' in your terminal.&lt;br /&gt;
&lt;br /&gt;
In the '''Mac''' terminal, vim ~/.zshrc and input the following command:&lt;br /&gt;
 $ alias aws='ssh &amp;lt;your-instance-username&amp;gt;@&amp;lt;ec2-xx-xx-xx-xx.compute-1.amazonaws.com&amp;gt;'&lt;br /&gt;
Now, whenever you type aws in your terminal, it will type your ssh command.&lt;br /&gt;
&lt;br /&gt;
In '''Cygwin''', vim ~/.bash_profile and input the following:&lt;br /&gt;
 export aws=&amp;quot;ssh &amp;lt;your-instance-username&amp;gt;@&amp;lt;ec2-xx-xx-xx-xx.compute-1.amazonaws.com&amp;gt;&amp;quot;&lt;br /&gt;
And you run this command by typing '''$aws'''&lt;br /&gt;
Also note that you may have to restart your terminal for this to take effect, or put the command in your ~/.bashrc file&lt;br /&gt;
&lt;br /&gt;
=== Install Essential Packages ===&lt;br /&gt;
&lt;br /&gt;
Recall that software installation in Linux instances is usually handled through a package manager, like '''yum'''.  For more information, refer to [[Linux#Repository-Based Package Managers|the Linux guide]].&lt;br /&gt;
&lt;br /&gt;
To make sure everything is working properly, '''install your first package(s) according to the ''Essential Packages'' subsection in the Linux guide.'''&lt;br /&gt;
&lt;br /&gt;
=== Set the Timezone ===&lt;br /&gt;
&lt;br /&gt;
'''Set your server to use US Central time (America/Chicago).'''  Instructions are in the Linux guide: [[Linux#Synchronizing Date and Time]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up the Apache Web Server ===&lt;br /&gt;
&lt;br /&gt;
You need to '''install the Apache web server on your EC2 instance'''.  Refer to [[Apache|the Apache guide]].&lt;br /&gt;
&lt;br /&gt;
In order for your web server to be accessible, you need to '''open up Port 80 on your EC2 instance'''.  Instructions are in the AWS guide: [[Amazon Web Services#Enabling Web Access to your EC2 Instance]]&lt;br /&gt;
&lt;br /&gt;
'''Enable the UserDir module in Apache.'''  Instructions are in the Apache guide: [[Apache#The UserDir Module]]&lt;br /&gt;
&lt;br /&gt;
=== Install PHP ===&lt;br /&gt;
&lt;br /&gt;
You need to '''install PHP on your EC2 server'''.  Instructions are at the top of the PHP guide: [[PHP]]&lt;br /&gt;
&lt;br /&gt;
You need to '''configure PHP to show errors'''.  Instructions are immediately below installation in the PHP guide.&lt;br /&gt;
&lt;br /&gt;
=== Learn about the PHP Language ===&lt;br /&gt;
&lt;br /&gt;
Before you can continue, you will need to make yourself acquainted with PHP language components.  Read the PHP guide for an overview: [[PHP#PHP Language Components]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up your Workspace ===&lt;br /&gt;
&lt;br /&gt;
You are now ready to set up the workspace that you will be using for the rest of the semester.  Follow the instructions in [[Workflow]] to:&lt;br /&gt;
&lt;br /&gt;
# Make an account on GitHub&lt;br /&gt;
# Setup a repo using GitHub Classroom&lt;br /&gt;
# Clone your CSE 330 repo from GitHub&lt;br /&gt;
# Install a text editor such as '''VSCode''' to write your assignments with&lt;br /&gt;
# Either install an FTP client, or use SFTP through command line, to transfer files from your local machine to your instance&lt;br /&gt;
&lt;br /&gt;
=== Calculator ===&lt;br /&gt;
&lt;br /&gt;
'''Make a calculator using PHP and an HTML form.'''  The form should have two number inputs.  The form should submit a GET request either back to the same page or to a different results page.  The calculator should support addition, subtraction, multiplication, and division by means of a radio button group on the page.  (Consider edge cases!)&lt;br /&gt;
&lt;br /&gt;
=== Git Tutorial ===&lt;br /&gt;
&lt;br /&gt;
Complete all of the levels of the Main and Remote sections of [https://learngitbranching.js.org/ this Git tutorial]. After you finish the tutorial, take two screenshots showing the completion of all of the levels of the Main and Remote sections. Place these two screenshots in your Module 2 Individual repo.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs (that means you and one other person) on this project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:1.3em; line-height:1.2em; color:blue;&amp;quot;&amp;gt;In this module, and all future modules, the group portion builds off of material you learn in the individual portion.  You should therefore complete the individual portions prior to working on the group portions.  (Trust us: it will make your life easier!)&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple File Sharing Site ===&lt;br /&gt;
&lt;br /&gt;
You will be making a simple file sharing site that supports uploading, viewing, and deleting files associated with various users.  Details:&lt;br /&gt;
&lt;br /&gt;
* You should have a file named '''users.txt''' stored in a secure place on your filesystem.  It should have at least three usernames, with one username per line.&lt;br /&gt;
*: Passwords add an extra layer of complexity (encryption) that we will cover in Module 3.  You will not earn credit for implementing passwords as your creative portion for this module.&lt;br /&gt;
* Users of the file sharing site should be able to enter their username and then log in.&lt;br /&gt;
*: You may implement logins using session variables, or you may implement them using a GET parameter that is passed between pages.  You will need to always use sessions starting in Module 3.&lt;br /&gt;
* Users should see a list of all files associated with their username after the log in.&lt;br /&gt;
* Users should be able to view, upload, and delete files associated with their username.&lt;br /&gt;
* The URI should NOT reveal the internal file structure of your web site.&lt;br /&gt;
** Example of what not to do:  http://www.example.com/download.php?file=/home/paul/file.txt&lt;br /&gt;
** Another bad example:  http://www.example.com/~user/file.txt&lt;br /&gt;
** Good example: http://www.example.com/view.php?user=music&amp;amp;name=file.txt&lt;br /&gt;
*: In general, don't reveal any internal information about the site.&lt;br /&gt;
*: '''Food for thought:''' Given that Apache processes (with the exception of the main process) do not run as root, but rather as the user apache, how can you allow both your user account and the php scripts to read and write the &lt;br /&gt;
*:necessary files?&lt;br /&gt;
*:: ''Hint:'' You shouldn't be storing the user-uploaded files in public_html (that is only the place for your own web-page files), &lt;br /&gt;
*::''Hint number 2:''  you will need to use chown to change permissions to let user apache have permissions on the user-files (that '''are not''' in the public_html folder). If you don't know what this does or how to do this, look at the [[Apache]] page&lt;br /&gt;
* You should customize your file sharing site by implementing an additional feature or two as part of the '''creative portion'''.&lt;br /&gt;
&lt;br /&gt;
You will probably find the PHP guide on this wiki to be helpful: [[PHP#Other PHP Tips]]&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 1]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to follow the conventions of FIEO (Filter Input and Escape Output)'''.  Things you should filter include file names, usernames, and so on.&lt;br /&gt;
* '''Your project must pass the W3C Validator with no errors or warnings'''.  For more information, see the HTML and CSS guide: [[HTML and CSS#Validation]]&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
We will be grading the following aspects of your work.  There are 120 points total. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Assignments (including code) must be committed to GitHub by the end of class on the due date. Commit early and often. Failing to commit by the end of class on the due date will result in a 0. &lt;br /&gt;
&lt;br /&gt;
_____________&lt;br /&gt;
&lt;br /&gt;
# '''Cloud Instance and Web Server (30 Points):'''&lt;br /&gt;
#* You can SSH into your instance using your own custom username and SSH key. Put a screenshot in your repository of your terminal SSH-ing into your instance (15 points)&lt;br /&gt;
#* Your custom username is able to perform SUDO commands. Put a screenshot in your repository of you successfully executing a command with sudo (5 points)&lt;br /&gt;
#* The time zone is correct on your instance. Put a screenshot in your repository of the results of the `date` command (5 points)&lt;br /&gt;
#* The UserDir Apache module is working. Place a file in /home/&amp;lt;username&amp;gt;/public_html and link to the file in your README.md (5 points)&lt;br /&gt;
# '''PHP Calculator (15 Points):'''&lt;br /&gt;
#* The calculator is able to perform all four functions with floating point numbers (2 points each, 8 points in total)&lt;br /&gt;
#* Each function is given as a radio button choice (4 points)&lt;br /&gt;
#* The calculator page passes the W3C HTML validator (3 points)&lt;br /&gt;
#* '''''Make sure you have a README.md file in your individual repo with the link to your calculator on your instance.''''' See the Creative Portion section for more information about .md files.&lt;br /&gt;
# '''Git Tutorial (20 Points):'''&lt;br /&gt;
#* Two screenshots showing the completion of all of the levels of the Main and Remote sections placed in your individual assignment repository.&lt;br /&gt;
# '''File Sharing Site (40 Points):'''&lt;br /&gt;
#* '''''File Management (25 Points):'''''&lt;br /&gt;
#** Users should not be able to see any files until they enter a username and log in (4 points)&lt;br /&gt;
#**: ''Remember that users.txt should be stored in a secure location on your filesystem.  That is, '''you should not be able to type any URL into your browser and see the raw users.txt file!'''''&lt;br /&gt;
#** Users can see a list of all files they have uploaded (4 points)&lt;br /&gt;
#** Users can open files they have previously uploaded (5 points)&lt;br /&gt;
#**: ''Note: Users should be able to open not only plain text files but also other file formats: images, spreadsheets, etc.''&lt;br /&gt;
#** Users can upload files (4 points)&lt;br /&gt;
#**: ''Note: Like users.txt, uploaded files should be stored in a secure location on your filesystem.  That is, '''do not keep your uploads directory underneath a directory served by Apache!'''''&lt;br /&gt;
#** Users can delete files.  If a file is &amp;quot;deleted&amp;quot;, it should actually be removed from the filesystem (4 points)&lt;br /&gt;
#** The directory structure is hidden. Users should not be able to access or view files by manipulating a URL. (2 points)&lt;br /&gt;
#** Users can log out (2 points)&lt;br /&gt;
#**: ''Note: If using session variables, you must ''actually'' log out the user by destroying their session; i.e., don't just redirect them to the login screen.''&lt;br /&gt;
#* '''''Best Practices (10 Points):'''''&lt;br /&gt;
#** Code is well formatted and easy to read, with proper commenting (4 points)&lt;br /&gt;
#** The site follows the FIEO philosophy (3 points)&lt;br /&gt;
#** All pages pass the W3C validator (3 points)&lt;br /&gt;
#* '''''Usability (5 Points):'''''&lt;br /&gt;
#** Site is intuitive to use and navigate (4 points)&lt;br /&gt;
#** Site is visually appealing (1 point)&lt;br /&gt;
# '''Creative Portion (15 Points)''' (see below)&lt;br /&gt;
#* '''''Make sure you have a README.md file in your group repo with the following:'''''&lt;br /&gt;
#** An .md file is a plain text file called a markdown file  [https://guides.github.com/features/mastering-markdown/ ] .  &lt;br /&gt;
#***The contents of your README.md file are shown on your repo, making it easier for us to grade&lt;br /&gt;
#*** You may style the page with bolding, hyperlings, images, block quotes and lists&lt;br /&gt;
#*** [http://dillinger.io/ This online markdown editor] makes it easy to learn this format  &lt;br /&gt;
#** The link to your file sharing site. '''''We need this to grade your work.'''''&lt;br /&gt;
#** A brief description of what you did for your creative portion&lt;br /&gt;
#** Any additional login details needed for the TA&lt;br /&gt;
&lt;br /&gt;
=== Creative Portion ===&lt;br /&gt;
&lt;br /&gt;
This module and all future modules will require that you invest some time into creating additional features for your group project.  Plan to invest at the very least 60 minutes of your time into the creative portion.  In the above rubric, viewing files is worth five and uploading is worth four. The creative portion is worth fifteen points; it should be a very sizable part of your project.&lt;br /&gt;
&lt;br /&gt;
* The creative portion is an opportunity for you to learn the material of your own interest.&lt;br /&gt;
* You will not earn credit for a creative-portion feature that simply rehashes something you've already done in a previous module.&lt;br /&gt;
&lt;br /&gt;
If you need ideas for a creative portion, or if you want to know whether or not your creative portion idea is &amp;quot;hard enough&amp;quot;, ask a TA.&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 2]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Node.JS&amp;diff=2914</id>
		<title>Node.JS</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Node.JS&amp;diff=2914"/>
		<updated>2024-03-22T23:01:41Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Installing Packages */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;AJAX is a useful technology for web applications that need to pull periodic updates from your server.  But what do you do when you have thousands of clients all requesting data that changes real-time?  A PHP+AJAX approach could choke without a lot of effort on your part.  It is situations like these that Node.js comes to the rescue. Node.js is a web framework, made in JavaScript, that's become extremely popular over the last few years.&lt;br /&gt;
&lt;br /&gt;
In general, JavaScript frameworks are very trendy right now; it can be hard to keep up with the new cool thing. In fact, there's a joke website https://dayssincelastjavascriptframework.com/, that &amp;quot;tracks&amp;quot; how long it's been since a new framework has come out.&lt;br /&gt;
&lt;br /&gt;
== Non-Blocking I/O ==&lt;br /&gt;
&lt;br /&gt;
You dabbled in the concept of non-blocking I/O when you implemented AJAX in the previous JavaScript module.  Node.js uses this execution model at its core.&lt;br /&gt;
&lt;br /&gt;
The core idea is the use of '''''anonymous functions''''' as ''callbacks'' for processing the results of intensive operations.  Consider the pseudo-code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// Blocking I/O Pseudo-Code&lt;br /&gt;
&lt;br /&gt;
var data = database.query(&amp;quot;select * from news&amp;quot;);&lt;br /&gt;
print data[0].title;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above pseudo-code queries a database, saves the result of the query in a variable named ''data'', and then prints out the first title in ''data''.  The problem arises when multiple clients all want to access the server at the same time.  ''In a blocking I/O model, a client needs to wait until all other clients are finished before it can start its process.''  With intensive operations and thousands of clients, this can easily crash your server!&lt;br /&gt;
&lt;br /&gt;
The solution is to use ''non-blocking I/O''.  Consider this revised pseudo-code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// Non-Blocking I/O Pseudo-Code&lt;br /&gt;
&lt;br /&gt;
database.query(&amp;quot;select * from news&amp;quot;, function(data){&lt;br /&gt;
	print data[0].title;&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The revised pseudo-code achieves the same end result as the first version.  However, ''it allows other clients to perform tasks while this process is waiting for the database to be queried!''  The code occurs in two parts: first, we start the query.  Second, ''when the query is complete'', our '''anonymous callback function''' is executed.  In Node.js, callback functions are usually passed one or more parameters.&lt;br /&gt;
&lt;br /&gt;
Better yet, with non-blocking I/O, you have no concurrency issues, because everything runs in just one thread.  Nifty!&lt;br /&gt;
&lt;br /&gt;
== Installing Node.js ==&lt;br /&gt;
&lt;br /&gt;
Run the following commands to install Node and NPM:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash&lt;br /&gt;
-&lt;br /&gt;
$ source ~/.bashrc&lt;br /&gt;
-&lt;br /&gt;
$ nvm install 16&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- The unofficial instructions for installing Node.js can be found here: https://gist.github.com/isaacs/579814&lt;br /&gt;
&lt;br /&gt;
There are several choices, but my favorite is probably ''use-nave-no-shell.sh''.&lt;br /&gt;
&lt;br /&gt;
The instructions at the above link have a couple bugs.  If you run this sequence of commands, Node and NPM will install correctly:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ mkdir ~/.nave&lt;br /&gt;
$ cd ~/.nave&lt;br /&gt;
$ wget http://github.com/isaacs/nave/raw/master/nave.sh&lt;br /&gt;
$ sudo ln -s $PWD/nave.sh /usr/local/bin/nave&lt;br /&gt;
$ chmod a+x nave.sh&lt;br /&gt;
$ sudo chown -R $USER:$USER /usr/local&lt;br /&gt;
$ nave usemain stable&lt;br /&gt;
$ curl -L https://www.npmjs.org/install.sh | sh&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Your First Node.js Application: Hello World ==&lt;br /&gt;
&lt;br /&gt;
Let's try running the example application given on the front page of nodejs.org:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
const http = require('http');&lt;br /&gt;
http.createServer(function (req, res) {&lt;br /&gt;
	res.writeHead(200, {&lt;br /&gt;
		'Content-Type': 'text/plain'&lt;br /&gt;
	});&lt;br /&gt;
	res.end('Hello World\n');&lt;br /&gt;
}).listen(3456);&lt;br /&gt;
console.log('Server running at http://localhost:3456/');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Paste the example into a file named `hello.js`, and then run it by calling `node hello.js`.  You should now be able to see your Hello World by visiting your server at port 3456!  (Press ^C to stop the application.)  '''Note:''' If you're running the code from your EC2 instance, you will need to open port 3456.&lt;br /&gt;
&lt;br /&gt;
Let's walk through each line in the above example.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;var http = require('http');&amp;lt;/code&amp;gt; enables us to use Node's built-in HTTP server.  We've been spoiled that languages like PHP automatically load all of the libraries that we need.  However, '''''most functionality in Node.js is NOT loaded by default.'''''  When you want to use any non-fundamental feature of Node, you need to ''require'' it into a variable, as this example does with the HTTP package.  You should be familiar with this concept when you needed to use ArrayList and other specialty packages in Java in CSE 132.&lt;br /&gt;
* &amp;lt;code&amp;gt;http.createServer(function (req, res) { ... }).listen(3456);&amp;lt;/code&amp;gt; uses the HTTP server API to listen for HTTP connections on port 3456.  The anonymous callback function will be called whenever a connection is made.&lt;br /&gt;
* &amp;lt;code&amp;gt;res.writeHead(200, { 'Content-Type': 'text/plain' });&amp;lt;/code&amp;gt; specifies the Content-Type header to be &amp;quot;text/plain&amp;quot;.&lt;br /&gt;
* &amp;lt;code&amp;gt;res.end('Hello World\n');&amp;lt;/code&amp;gt; writes &amp;quot;Hello World&amp;quot; to the response.&lt;br /&gt;
&lt;br /&gt;
Note the use of non-blocking I/O, even in this one little example.  ''Whenever a connection is made, the callback function will be called and passed parameters associated with that connection.''&lt;br /&gt;
&lt;br /&gt;
== A Static File Server Using Node.js ==&lt;br /&gt;
&lt;br /&gt;
Node.js does not automatically serve up static files in the way that an Apache/PHP does.  We need to either use an extension that handles this for us, like Express, or we need to write our own code to make a simple static file server.  The latter option is really not all that difficult, and it gives good insight into how a static file server works.&lt;br /&gt;
&lt;br /&gt;
=== Installing Packages ===&lt;br /&gt;
&lt;br /&gt;
In order for the example code below to work, you need to install the ''mime'' package.  To do this, '''cd to the working directory where you will save your Node.js JavaScript file''' and run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;$ npm install mime@3.0.0 --save&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''npm'' is the package manager for Node.js.  Unlike all of the package managers we've used up to this point, ''npm'' installs dependencies locally, ''not'' globally.  This means that you can have two different projects using different versions of the same package.  ''npm'' will create a ''node_modules'' directory in the CWD and will install the packages into it.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' When using npm to install local dependencies, '''''do not use sudo'''''.  It will screw up your file permissions.&lt;br /&gt;
&lt;br /&gt;
=== Static Fileserver Code ===&lt;br /&gt;
&lt;br /&gt;
The following code will make an HTTP server on port 3456 that serves up all static files in &amp;lt;STATIC DIRECTORY NAME&amp;gt; relative to app.js.&lt;br /&gt;
&lt;br /&gt;
'''Make an attempt to understand this code.'''  It's important that you are comfortable with the non-blocking nature, as well as how we handle file I/O. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
// Require the functionality we need to use:&lt;br /&gt;
var http = require('http'),&lt;br /&gt;
	url = require('url'),&lt;br /&gt;
	mime = require('mime'),&lt;br /&gt;
	path = require('path'),&lt;br /&gt;
	fs = require('fs');&lt;br /&gt;
&lt;br /&gt;
// Make a simple fileserver for all of our static content.&lt;br /&gt;
// Everything underneath &amp;lt;STATIC DIRECTORY NAME&amp;gt; will be served.&lt;br /&gt;
var app = http.createServer(function(req, resp){&lt;br /&gt;
	var filename = path.join(__dirname, &amp;quot;&amp;lt;STATIC DIRECTORY NAME&amp;gt;&amp;quot;, url.parse(req.url).pathname);&lt;br /&gt;
	(fs.exists || path.exists)(filename, function(exists){&lt;br /&gt;
		if (exists) {&lt;br /&gt;
			fs.readFile(filename, function(err, data){&lt;br /&gt;
				if (err) {&lt;br /&gt;
					// File exists but is not readable (permissions issue?)&lt;br /&gt;
					resp.writeHead(500, {&lt;br /&gt;
						&amp;quot;Content-Type&amp;quot;: &amp;quot;text/plain&amp;quot;&lt;br /&gt;
					});&lt;br /&gt;
					resp.write(&amp;quot;Internal server error: could not read file&amp;quot;);&lt;br /&gt;
					resp.end();&lt;br /&gt;
					return;&lt;br /&gt;
				}&lt;br /&gt;
				&lt;br /&gt;
				// File exists and is readable&lt;br /&gt;
				var mimetype = mime.getType(filename);&lt;br /&gt;
				resp.writeHead(200, {&lt;br /&gt;
					&amp;quot;Content-Type&amp;quot;: mimetype&lt;br /&gt;
				});&lt;br /&gt;
				resp.write(data);&lt;br /&gt;
				resp.end();&lt;br /&gt;
				return;&lt;br /&gt;
			});&lt;br /&gt;
		}else{&lt;br /&gt;
			// File does not exist&lt;br /&gt;
			resp.writeHead(404, {&lt;br /&gt;
				&amp;quot;Content-Type&amp;quot;: &amp;quot;text/plain&amp;quot;&lt;br /&gt;
			});&lt;br /&gt;
			resp.write(&amp;quot;Requested file not found: &amp;quot;+filename);&lt;br /&gt;
			resp.end();&lt;br /&gt;
			return;&lt;br /&gt;
		}&lt;br /&gt;
	});&lt;br /&gt;
});&lt;br /&gt;
app.listen(3456);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Port 3456 ===&lt;br /&gt;
&lt;br /&gt;
We are running our server on port 3456 as opposed to the default web server port, which of course is 80.  We therefore need to open our Node.js application like this:&lt;br /&gt;
&lt;br /&gt;
http://ec2-xx-xx-xx-xx.compute-1.amazonaws.com:3456/path.extension&lt;br /&gt;
&lt;br /&gt;
However, this won't work on the first time.  ''Why?'' (Try to figure this out on your own before reading the next paragraph.)&lt;br /&gt;
&lt;br /&gt;
We need to open port 3456 on our Amazon EC2 instance.  Remember when you opened port 80 way back in Module 2?  We need to do the same sort of procedure again now.&lt;br /&gt;
&lt;br /&gt;
# Log into your EC2 management console&lt;br /&gt;
# Go to &amp;quot;Security Groups&amp;quot;&lt;br /&gt;
# Select your security group from Module 2&lt;br /&gt;
# Under &amp;quot;Inbound&amp;quot;, create a custom TCP rule for port 3456, and apply your changes.&lt;br /&gt;
&lt;br /&gt;
== Node.js Security ==&lt;br /&gt;
&lt;br /&gt;
Just because we're writing in JavaScript doesn't mean that we can forget about the security practices you've been learning in the last three months of CSE 330.  XSS is still a problem, as is the use of ''eval'', CSRF attacks, and so on.&lt;br /&gt;
&lt;br /&gt;
The two links below have good information about security vulnerabilities specific to Node.js that you should think about when crafting your application.&lt;br /&gt;
&lt;br /&gt;
# Book from PragProg ($24, 2015): https://pragprog.com/book/kdnodesec/secure-your-node-js-web-application&lt;br /&gt;
# Slideshow from a Switzerland Conference on Application Security (2012): http://www.slideshare.net/ASF-WS/asfws-2012-nodejs-security-old-vulnerabilities-in-new-dresses-par-sven-vetsch&lt;br /&gt;
&lt;br /&gt;
== Node.js Conventions ==&lt;br /&gt;
&lt;br /&gt;
There ought to be a standard way to save metadata about your app, right?  Well, ''npm'' introduces a straightforward way to do this in the form of a ''package.json'' file.&lt;br /&gt;
&lt;br /&gt;
To make your ''npm'' file with a step-by-step prompt, run in your project root directory:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ npm init&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
One nifty feature of ''package.json'' is the way it automatically handles dependencies.  For example, you can put the following lines in your ''package.json'':&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;quot;dependencies&amp;quot;: {&lt;br /&gt;
    &amp;quot;mime&amp;quot;: &amp;quot;~2.4.6&amp;quot;,&lt;br /&gt;
    &amp;quot;socket.io&amp;quot;: &amp;quot;~1.0.0&amp;quot;&lt;br /&gt;
  },&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, back on the command line, when you run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ npm install&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
it automatically installs the dependencies for you!  No more headaches of trying to figure out which modules you need to install; all that information is saved for you in your code base.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' Once you set up your ''package.json'' file, you can automatically add a dependency to it by using the ''--save'' argument on ''npm install'': &amp;lt;code&amp;gt;npm install --save socket.io&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 7]]&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Linux&amp;diff=2911</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Linux&amp;diff=2911"/>
		<updated>2024-01-23T04:07:12Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Adding a User to the Sudoers List */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[wikipedia:Linux|Linux]] is an [[wikipedia:Free and open-source software|open-source]] operating system based on [[wikipedia:UNIX|UNIX]].  Linux is highly versatile and is used in a wide range of applications.  [[wikipedia:Desktop Linux|Desktop Linux]] is Linux with a GUI (like Microsoft Windows or Mac OS X); Desktop Linux is popular in niche markets, and it is used widely in developing countries.&lt;br /&gt;
&lt;br /&gt;
Linux is the most widely used operating system for web servers.  In CSE330, we will be interacting with Linux from the command line.  This article covers the tools you need to make the best use of Linux.&lt;br /&gt;
&lt;br /&gt;
== Linux Distributions ==&lt;br /&gt;
&lt;br /&gt;
The open-source community is responsible for the development of many different [[wikipedia:Linux distributions|distributions]] of Linux.  Distributions, or ''distros'', are different &amp;quot;flavors&amp;quot; of the Linux operating system with different objectives.&lt;br /&gt;
&lt;br /&gt;
There are hundreds of distributions of Linux.  Three of the main branches are [[wikipedia:Debian|Debian]], [[wikipedia:SuSE|SuSE]] (based on [[wikipedia:Slackware|Slackware]]), and [[wikipedia:Red Hat Enterprise Linux|Red Hat Enterprise Linux (RHEL)]].&lt;br /&gt;
&lt;br /&gt;
For CSE 330, you'll be using a version of Red Hat Enterprise Linux. &lt;br /&gt;
&lt;br /&gt;
=== Red Hat Enterprise Linux (RHEL) ===&lt;br /&gt;
&lt;br /&gt;
Red Hat Enterprise Linux, or '''RHEL''', was first introduced in 1994.  RHEL is known for being a good choice for enterprises that wish to use Linux as their primary OS.  RHEL has an abundance of administration tools.&lt;br /&gt;
&lt;br /&gt;
The Linux Lab in Lopata Hall uses '''[[wikipedia:Fedora Linux|Fedora Linux]]''', a desktop distribution based on RHEL.  '''[[wikipedia:CentOS|CentOS]]''' is a popular RHEL derivative that is widely used in web servers.  The '''[[wikipedia:Amazon Machine Image|Amazon EC2 Linux AMI]]''' is derived from CentOS, making it a distribution in the RHEL family.&lt;br /&gt;
&lt;br /&gt;
=== Special Note: Linux Kernel and Modules ===&lt;br /&gt;
{{XKCD&lt;br /&gt;
|id=619&lt;br /&gt;
|name=supported_features&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
What separates Linux from other Unix variants is its kernel. The kernel is the most important component of the operating system and is responsible for scheduling processes, providing access to the hardware devices, allocating memory to the programs, and so on.&lt;br /&gt;
&lt;br /&gt;
The Linux kernel uses both monolithic and modular approaches. A monolithic kernel is a single program that contains all the code so any addition to kernel (such as code to access a driver) requires recompiling the code. A monolithic kernel is usually a little faster and could have a smaller size since only the absolutely necessary code is there. The modular kernel, on the other hand, enables dynamic loading and unloading  of kernel code, called ''modules''. Typical modules include device drivers. Thanks to this modular approach, Linux seldom requires a reboot after installing a new device.&lt;br /&gt;
&lt;br /&gt;
== Bash ==&lt;br /&gt;
&lt;br /&gt;
In this course, you will be interacting with Linux primarily on the command line.  The most widespread ''command line language'' is '''Bash'''.  This is described in more detail in [[Bash|the Bash guide]].&lt;br /&gt;
&lt;br /&gt;
== Files and Permissions ==&lt;br /&gt;
&lt;br /&gt;
At the core of a Unix-based operating system is a directory structure with files and permissions.&lt;br /&gt;
&lt;br /&gt;
=== Filesystem Hierarchy ===&lt;br /&gt;
&lt;br /&gt;
The root directory of Linux contains a dozen or so subdirectories, each with a specific purpose:&lt;br /&gt;
&lt;br /&gt;
* '''/bin''' contains [[Bash#Running Programs|binaries]] used by all users&lt;br /&gt;
* '''/sbin''' contains system binaries typically used only by the system administrator&lt;br /&gt;
* '''/lib''' contains libraries for the binaries found in '''/bin''' and '''/sbin'''&lt;br /&gt;
* '''/etc''' contains configuration files&lt;br /&gt;
** '''/etc/yum.conf''' Configuration file for yum&lt;br /&gt;
** '''/etc/yum/yum.repos.d''' Directory containing .repo files for online repositories&lt;br /&gt;
** '''/etc/crontab''' System-wide crontab file&lt;br /&gt;
** '''/etc/fstab''' Information about default partitions to be mounted&lt;br /&gt;
** '''/etc/group''' List of groups in the system&lt;br /&gt;
** '''/etc/hosts''' List of IP addresses with their names&lt;br /&gt;
** '''/etc/inittab''' What to do at each run-level&lt;br /&gt;
** '''/etc/inetd.conf''' Configuration file for some internet services (replaced by xinetd.* in most systems)&lt;br /&gt;
** '''/etc/modules.conf''' Module information for the boot&lt;br /&gt;
** '''/etc/motd''' Message to be seen at the login prompt&lt;br /&gt;
** '''/etc/passwd''' User information&lt;br /&gt;
** '''/etc/profile''' System level initial file for sh and its derivatives&lt;br /&gt;
** '''/etc/shadow''' User passwords&lt;br /&gt;
* '''/dev''' contains device files&lt;br /&gt;
* '''/proc''' contains information on currently running processes&lt;br /&gt;
* '''/var''' contains files whose contents is expected to change&lt;br /&gt;
** '''/var/log''' contains system log files&lt;br /&gt;
*** '''/var/log/messages''' System/Kernel messages&lt;br /&gt;
*** '''/var/log/syslog''' System log (mostly for Daemons)&lt;br /&gt;
*** '''/var/log/wtmp'''' User access log (binary)&lt;br /&gt;
*** '''/var/log/dmesg''' Boot-up messages&lt;br /&gt;
*** '''/var/log/auth.log''' Authorization logs&lt;br /&gt;
** '''/var/lib''' contains packages and database files&lt;br /&gt;
** '''/var/spool''' contains print queues&lt;br /&gt;
* '''/tmp''' contains temporary files that are deleted at system reboot&lt;br /&gt;
* '''/usr''' contains user programs&lt;br /&gt;
** '''/usr/bin''' contains binaries for user programs&lt;br /&gt;
** '''/usr/sbin''' contains binaries for system administrators&lt;br /&gt;
** '''/usr/lib''' contains libraries for '''/usr/bin''' and '''/usr/sbin'''&lt;br /&gt;
** '''/usr/local''' contains programs that you install from source&lt;br /&gt;
* '''/home''' contains users' home directories&lt;br /&gt;
* '''/root''' is root's home directory&lt;br /&gt;
* '''/boot''' contains boot loader files (do not touch unless you know what you are doing!)&lt;br /&gt;
* '''/opt''' contains optional add-on applications&lt;br /&gt;
* '''/mnt''' is where system administrators can mount filesystems&lt;br /&gt;
* '''/media''' contains links to removable media devices (for example, CDs)&lt;br /&gt;
* '''/srv''' contains site-specific data which are served by the system&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For more information, see the Wikipedia article on the [[wikipedia:Filesystem Hierarchy Standard|Filesystem Hierarchy Standard]].&lt;br /&gt;
&lt;br /&gt;
=== File Permissions ===&lt;br /&gt;
&lt;br /&gt;
Every file in Linux has permissions that define which users can Read, Write, and Execute it.  Every file has an owner and a group.  The permissions for a file are set on three levels: User (owner), Group, and Other.&lt;br /&gt;
&lt;br /&gt;
==== Symbolic Notation ====&lt;br /&gt;
&lt;br /&gt;
When you view the permissions of a file in Linux, they will most often be displayed in ''symbolic notation''.  Symbolic notation consists of 10 characters: the first defines the file type, and then there are three characters each for User, Group, and Other permissions.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;-r--r--r--&amp;lt;/code&amp;gt; is a normal file that is readable by all users but writable or executable by no one.&lt;br /&gt;
* &amp;lt;code&amp;gt;-rwxr-xr-x&amp;lt;/code&amp;gt; is a normal file that is readable and executable by everyone but only writable by User (the file's owner).  This is the most common permission set.&lt;br /&gt;
&lt;br /&gt;
==== Viewing File Permissions ====&lt;br /&gt;
&lt;br /&gt;
To view the permissions of all files in a certain directory, run the binary &amp;lt;code&amp;gt;ls -l&amp;lt;/code&amp;gt; in Bash:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ls -l   # displays a list of all files in a directory with their permissions in symbolic notation&lt;br /&gt;
total 16&lt;br /&gt;
lrwxr-xr-x  1 sffc  wheel   6 Aug  9 09:13 link -&amp;gt; myfile.txt&lt;br /&gt;
-rwxr--r--  1 sffc  wheel  12 Aug  9 09:13 myfile.txt&lt;br /&gt;
$ ls -l myfile.txt   # displays the permissions of only myfile.txt&lt;br /&gt;
-rwxr--r--  1 sffc  wheel  12 Aug  9 09:13 myfile.txt&lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Setting File Permissions ====&lt;br /&gt;
&lt;br /&gt;
Linux comes with several useful binaries for setting file permissions.&lt;br /&gt;
&lt;br /&gt;
* '''chmod''' is used for setting permissions&lt;br /&gt;
* '''chown''' is used for setting a file's owner&lt;br /&gt;
* '''chgrp''' is used for setting a file's group&lt;br /&gt;
&lt;br /&gt;
Some examples are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ chmod a+x myfile.txt   # turns on the Execute option for all users&lt;br /&gt;
$ chmod o-w myfile.txt   # turns off the Write option for Other users&lt;br /&gt;
$ chmod u+wx-r myfile.txt   # turns on the Write and Execute options for User (the file's owner) and also turns off the Read option for User&lt;br /&gt;
$ chown todd myfile.txt   # sets the owner of myfile.txt to the user todd.  Note: First comes the user, then comes the filename: not the other way around!&lt;br /&gt;
$ chgrp staff myfile.txt   # sets the group of myfile.txt to usergroup staff&lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information, see https://www.linux.com/training-tutorials/how-manage-file-and-folder-permissions-linux/&lt;br /&gt;
&lt;br /&gt;
=== The . and .. Directories ===&lt;br /&gt;
&lt;br /&gt;
The '''.''' directory is a reference to the current directory.   The '''..''' directory brings you one level up in the filesystem.&lt;br /&gt;
&lt;br /&gt;
=== Symbolic Links ===&lt;br /&gt;
&lt;br /&gt;
A [[wikipedia:Symbolic link|symbolic link]], or ''symlink'', is basically a link from one spot in the filesystem to another.  You can think of them like ''aliases'' in Mac OS X.  To create a a symlink, use the ''ln -s'' command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ln -s /path/to/file.txt /path/to/link   # creates a symlink to file.txt at /path/to/link&lt;br /&gt;
&lt;br /&gt;
# Example:&lt;br /&gt;
$ ln -s /home/todd/instructions.doc /var/www/public_html/classes/instructions.doc   # creates a symlink in the web server to instructions.doc&lt;br /&gt;
$ vi /var/www/public_html/classes/instructions.doc   # changes to the symbolic link will be reflected in the original file&lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User Management ==&lt;br /&gt;
&lt;br /&gt;
=== Adding a New User ===&lt;br /&gt;
&lt;br /&gt;
To create a new user, use the '''useradd''' command.  Then, set a password for that user using the '''passwd''' command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo useradd -r -m -c &amp;quot;&amp;lt;My Full Name&amp;gt;&amp;quot; &amp;lt;myUserName&amp;gt;&lt;br /&gt;
$ sudo passwd &amp;lt;myUserName&amp;gt;&lt;br /&gt;
Enter new UNIX password: &lt;br /&gt;
Retype new UNIX password: &lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' If Linux doesn't like your command, first check your syntax and then try it with single quotes around your full name and password instead of double quotes. If this works it is likely that you used some special characters in your password such as '!', which serves a special purpose in the shell. This is because Linux takes parameters enclosed in double quotes as one string, but still looks for special characters inside of the string and acts in accordance with their normal meaning. On the other hand, single quotes tell the shell to ignore any special characters within.&lt;br /&gt;
&lt;br /&gt;
=== Adding a User to the Sudoers List ===&lt;br /&gt;
&lt;br /&gt;
For security reasons, you should never SSH into your server as the root user.  Instead, you should use a normal user to whom you give '''sudo''' privileges.  (For more detail on sudo, see [[Linux#SUDO|the Linux guide]].)&lt;br /&gt;
&lt;br /&gt;
To give a user sudo privileges, use the command '''visudo''', which opens up the SUDO configuration file in the system's default text editor.  (Never edit the file ''/etc/sudoers'' directly!)  SUDO users are specified using lines similar to&lt;br /&gt;
&lt;br /&gt;
 alice   ALL=(ALL) ALL&lt;br /&gt;
&lt;br /&gt;
Add that line immediately below  the line defining '''root''':&lt;br /&gt;
&lt;br /&gt;
 root   ALL=(ALL) ALL&lt;br /&gt;
&lt;br /&gt;
When you are finished, save and close the file.  For more information on editing files on the command line, refer to [[#File Editors|the section about File Editors in this guide]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- AS of 02/19/2017, this link isn't available in HTTPS. --&amp;gt;&lt;br /&gt;
In this case, '''alice''' will be able to run any command with SUDO privileges on the computer.   &lt;br /&gt;
&lt;br /&gt;
'''Note:''' The visudo utility is especially useful because it not only locks the sudoers file against simultaneous edits, but it also checks the file for syntax errors when you quit. Therefore, it is always recommended that you use visudo to change the sudoers list rather than attempting to modify it directly.&lt;br /&gt;
&lt;br /&gt;
== Networking ==&lt;br /&gt;
&lt;br /&gt;
In Linux, you can see your network information by typing '''ifconfig'''. This command shows the status information of each network interface, including the IP address you will need to remotely connect to your instance. The interface ''lo'' is the special loopback interface with IP address 127.0.0.1.  This refers to your local machine and any connection from your machine to your machine goes through this pseudo-interface.  Typical network interfaces include ''eth0'', ''eth1'',..., ''wlan0'', etc. Ethernet cards are represented with ''ethX''.  In the past, most wireless cards showed up as ''wlanX'', but it is also common now for them to be represented with ''ethX'' names. ''ifconfig'' also gives information such as hardware address (MAC), netmask, and broadcast addresses.&lt;br /&gt;
&lt;br /&gt;
You can start or stop networking by calling ''/etc/init.d/networking'' script. As with most ''/etc/init.d'' scripts, this script takes several options, such as ''start'', ''stop'', ''restart''.  Note even if you stop networking, you would still have your lo interface. You can look at the code of the script to find out what it actually does. You can also stop or start individual interfaces by using the '''ifup''' and '''ifdown''' commands.&lt;br /&gt;
&lt;br /&gt;
The network configuration files are stored in ''/etc/network''. ''/etc/network/interfaces'' contains the defaults for each interface. For xample, you could specify static IP, netmask, network, broadcast and default gateway for an interface here, but you should not need to edit this files in general.  These default options can be changed with the '''ifconfig''' command. The ''/etc/network/if-down.d'' and ''/etc/network/if-up.d'' directories contain the scripts that are going to be executed when an interface is turned on or off.  Of course, most modern Linux distributions have GUI tools for doing network configuration more easily, and you shouldn't need to change anything for the purposes of this course.&lt;br /&gt;
&lt;br /&gt;
== Synchronizing Date and Time ==&lt;br /&gt;
&lt;br /&gt;
In order to avoid setting your system's time manually at every daylight savings change, you can use a Network Time Server via the Network Time Protocol (NTP).&lt;br /&gt;
&lt;br /&gt;
The NTP Daemon comes pre-installed on EC2 AMI instances.&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
=== Setting Timezone ===&lt;br /&gt;
&lt;br /&gt;
Your server is probably not set to the correct timezone by default.&lt;br /&gt;
&lt;br /&gt;
The timezone files are in the directory ''/usr/share/zoneinfo''. They are further organized within subdirectories grouped by region.  For instance, Rome's time zone file is stored within ''/usr/share/zoneinfo/Europe''.&lt;br /&gt;
&lt;br /&gt;
In order to set the time zone, simply copy the desired time zone file to our ''/etc'' directory as a new file named &amp;quot;localtime&amp;quot;.  For example, to set the the machine's system time to Rome's time zone, we would enter the command&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo cp /usr/share/zoneinfo/Europe/Rome /etc/localtime&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''ntp'' uses ''/etc/ntp.conf'' configuration file to find the ostnames of remote time servers.  The defaults here are probably fine.&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Installing Software ==&lt;br /&gt;
&lt;br /&gt;
The package management tool in Red Hat Enterprise Linux (and therefore also your Amazon EC2 instance) is '''rpm'''.   If you have an ''rpm'' package, you can install it by&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ rpm -i somepackage.rpm&lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This requires that ''somepackage.rpm'' be in your current directory, which means you will have to download the file yourself (or create it). It requires you to manually install any dependencies the package has.&lt;br /&gt;
&lt;br /&gt;
=== Repository-Based Package Managers ===&lt;br /&gt;
&lt;br /&gt;
A better alternative is to use a repository-based package manager.  In RHEL, this is '''yum'''.&lt;br /&gt;
&lt;br /&gt;
Before you install new software, you need to ensure that your local list of available packages is up-to-date.  Run the following commands to perform this operation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;gt;&lt;br /&gt;
yum check-update&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you have ensured that your package list is synced with the remote repository, you can start installing packages.  To install a package, the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;gt;&lt;br /&gt;
yum install &amp;lt;package-name&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get a permission denied error, try sudoing the command, like '''sudo apt-get install &amp;lt;xxxx&amp;gt;'''&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would install ''lynx'', a command-line web browser, in your RHEL Linux distribution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ lynx --version   # is lynx installed?&lt;br /&gt;
-bash: lynx: command not found&lt;br /&gt;
$ sudo yum check-update   # sync package lists with the remote repositories&lt;br /&gt;
$ sudo yum install lynx    # install the lynx package&lt;br /&gt;
Downloading Packages:&lt;br /&gt;
lynx-2.8.6-27.6.amzn1.i686.rpm        | 1.8 MB     00:00     &lt;br /&gt;
Running rpm_check_debug&lt;br /&gt;
Running Transaction Test&lt;br /&gt;
Transaction Test Succeeded&lt;br /&gt;
Running Transaction&lt;br /&gt;
  Installing : lynx-2.8.6-27.6.amzn1.i686             1/1 &lt;br /&gt;
&lt;br /&gt;
Installed:&lt;br /&gt;
  lynx.i686 0:2.8.6-27.6.amzn1                                                                                                                                                                                                                &lt;br /&gt;
&lt;br /&gt;
Complete!&lt;br /&gt;
$ lynx --version   # test again to see if we have lynx installed&lt;br /&gt;
Lynx Version 2.8.6rel.5 (09 May 2007)&lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also search for available packages by name or by the name of a file that they install.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ yum search lynx   # search for packages whose name contains lynx&lt;br /&gt;
======= N/S Matched: lynx =======&lt;br /&gt;
lynx.i686 : A text-based Web browser&lt;br /&gt;
$ yum provides lynx   # search for packages that install a file or command named lynx&lt;br /&gt;
lynx-2.8.6-27.6.amzn1.i686 : A text-based Web browser&lt;br /&gt;
Repo        : installed&lt;br /&gt;
Matched from:&lt;br /&gt;
Other       : Provides-match: lynx&lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The list of repositories that '''yum''' searches is located at &amp;lt;code&amp;gt;/etc/yum.conf&amp;lt;/code&amp;gt;.  The list of repositories that '''apt''' searches is located at &amp;lt;code&amp;gt;/etc/apt/sources.list&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
=== Essential Packages ===&lt;br /&gt;
&lt;br /&gt;
To save you some headaches later on, it is recommended that you install a few essential package bundles when you first create a new Linux instance.  These packages include things like Make and a C compiler.&lt;br /&gt;
&lt;br /&gt;
'''RHEL:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo yum groupinstall &amp;quot;Development Tools&amp;quot;&lt;br /&gt;
$ sudo yum install kernel-devel kernel-headers&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Searching for Packages ===&lt;br /&gt;
&lt;br /&gt;
You can search for packages by name, command, and so on.  For example, to search for all packages relating to &amp;quot;lynx&amp;quot;, you could do:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''RHEL:'''&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ yum search lynx&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Command Reference ==&lt;br /&gt;
Earlier, you saw that '''cat''' is a command that shows the contents of a file.  Below is a list of other useful commands in Linux.&lt;br /&gt;
&lt;br /&gt;
=== Navigation and File Management ===&lt;br /&gt;
&lt;br /&gt;
* '''ls''' List file(s) in current working directory&lt;br /&gt;
** '''ll''' Shortcut to '''ls -l'''.  List files with more details than '''ls'''.  Only available in certain distributions&lt;br /&gt;
* '''cd''' Change working directory.  Note: cd called without any arguments moves you to your home directory&lt;br /&gt;
* '''cp''' Copy a file&lt;br /&gt;
* '''mv''' Move or rename a file&lt;br /&gt;
* '''rm''' Remove a file&lt;br /&gt;
** '''rm -r''' Remove a directory and all files in it&lt;br /&gt;
* '''ln -s''' Create a symlink to a file&lt;br /&gt;
* '''mkdir''' Create a directory&lt;br /&gt;
* '''rmdir''' Remove a directory (directory must be empty; if it's not, use '''rm -r''')&lt;br /&gt;
* '''cat''' Display the contents of a file&lt;br /&gt;
* '''less''' Display the contents of a file, wait for the user at each page&lt;br /&gt;
* '''tail''' Display the last 20 lines of a file&lt;br /&gt;
** '''tail -f''' Display the last 20 lines of a file and then wait for changes, displaying them as they occur.  Useful for monitoring log files.&lt;br /&gt;
* '''chown''' Change the owner of a file&lt;br /&gt;
* '''chgrp''' Change the group of a file&lt;br /&gt;
* '''chmod''' Change the security permissions of a file&lt;br /&gt;
* '''grep''' Display the lines of a file matching a user specified string&lt;br /&gt;
* '''diff''' Display the difference between two files&lt;br /&gt;
&lt;br /&gt;
=== System Administration ===&lt;br /&gt;
&lt;br /&gt;
* '''df''' Display free diskspace&lt;br /&gt;
* '''du''' Display disk usage&lt;br /&gt;
* '''free''' Display memory usage information&lt;br /&gt;
* '''date''' Display current time and date&lt;br /&gt;
* '''top''' Display the CPU and Memory usages of current processes&lt;br /&gt;
* '''ps''' Display current processes&lt;br /&gt;
* '''kill''' Terminate a running process&lt;br /&gt;
* '''killall''' Terminate the running process matching user specified criterias&lt;br /&gt;
* '''ping hostname''' Ping a host&lt;br /&gt;
* '''host''' Get the IP address of a host&lt;br /&gt;
* '''passwd''' Change the user password&lt;br /&gt;
* '''su user''' Switch to the privileges of another user&lt;br /&gt;
* '''shutdown''' Power off the computer&lt;br /&gt;
* '''reboot''' Reboot the computer&lt;br /&gt;
* '''clear''' Clear the terminal&lt;br /&gt;
* '''ifconfig''' Display/Configure a network device&lt;br /&gt;
* '''file''' Show the file type&lt;br /&gt;
* '''lsmod''' Display loaded kernel modules&lt;br /&gt;
* '''insmod''' Install a kernel module&lt;br /&gt;
* '''modprobe''' Load a kernel module (also load the dependencies)&lt;br /&gt;
* '''adduser''' Add a new user&lt;br /&gt;
* '''exit''' Exit from a shell&lt;br /&gt;
* '''lpr''' Print a file&lt;br /&gt;
* '''head''' Display  lines at the beginning of a file&lt;br /&gt;
* '''tail''' Display lines at the end of a file&lt;br /&gt;
* '''pwd''' Display the name of the current working directory&lt;br /&gt;
* '''lsof''' Open files in the system&lt;br /&gt;
* '''netstat''' Statistics related to open sockets&lt;br /&gt;
* '''vmstat''' Reports information about processes, memory, IO, and CPU&lt;br /&gt;
&lt;br /&gt;
=== File Editors ===&lt;br /&gt;
{{XKCD&lt;br /&gt;
|name=real_programmers&lt;br /&gt;
|id=378&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
It is sometimes convenient to edit files using the command line.  Three widely-used command line text editors are '''vi''', '''emacs''', and '''nano'''.&lt;br /&gt;
&lt;br /&gt;
==== Vi ====&lt;br /&gt;
&lt;br /&gt;
To edit a file using Vi, use the command '''vi'''.  You will see something like this:&lt;br /&gt;
&lt;br /&gt;
 .&lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 &amp;quot;myfile.txt&amp;quot; [New File]&lt;br /&gt;
&lt;br /&gt;
To insert text into the file, press '''i''' once, then type away:&lt;br /&gt;
&lt;br /&gt;
 Hello World&lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 -- INSERT -- &lt;br /&gt;
&lt;br /&gt;
To leave insert mode, press ESC.&lt;br /&gt;
&lt;br /&gt;
To save your file, type the command ''':w''' and press Enter.&lt;br /&gt;
&lt;br /&gt;
 Hello World&lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 &amp;quot;myfile.txt&amp;quot; [New] 1L, 12C written&lt;br /&gt;
&lt;br /&gt;
To save and then close your file, type the command ''':wq'''.  (To close the file without saving, use the command ''':q!''')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For more vi commands, see https://ss64.com/vi.html&lt;br /&gt;
&lt;br /&gt;
==== Emacs ====&lt;br /&gt;
&lt;br /&gt;
To edit a file using emacs, use the command '''emacs'''.  You can start typing immediately:&lt;br /&gt;
&lt;br /&gt;
 Hello World&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 -uuu:**-F1  myfile.txt     All L1     (Text)----------&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
To save a file, type '''C-x C-s''' (that means Control-X, then Control-S):&lt;br /&gt;
&lt;br /&gt;
 Hello World&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 -uuu:---F1  myfile.txt     All L1     (Text)----------&lt;br /&gt;
 Wrote /home/todd/myfile.txt&lt;br /&gt;
&lt;br /&gt;
To quit emacs, type '''C-x C-c'''.  (It will ask you whether or not to save the file if you've made changes.)&lt;br /&gt;
&lt;br /&gt;
For more emacs commands, see http://souptonuts.sourceforge.net/chirico/emacs_ref.html&lt;br /&gt;
&lt;br /&gt;
==== Nano ====&lt;br /&gt;
&lt;br /&gt;
To edit a file using nano, use the command '''nano'''.  You can start editing the file immediately:&lt;br /&gt;
&lt;br /&gt;
   GNU nano 2.0.6               File: myfile.txt                                      &lt;br /&gt;
 &lt;br /&gt;
 Hello World&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 ^G Get Help   ^O WriteOut   ^R Read File  ^Y Prev Page  ^K Cut Text   ^C Cur Pos&lt;br /&gt;
 ^X Exit       ^J Justify    ^W Where Is   ^V Next Page  ^U UnCut Text ^T To Spell&lt;br /&gt;
&lt;br /&gt;
Nano tells you the commands you need right there so you don't have to always keep looking them up like with Vi and Emacs.&lt;br /&gt;
&lt;br /&gt;
For more detail on Nano commands, see http://www.nano-editor.org/dist/v2.2/nano.html&lt;br /&gt;
&lt;br /&gt;
== Linux Resources ==&lt;br /&gt;
&lt;br /&gt;
[http://www.yolinux.com/TUTORIALS/LinuxTutorialSysAdmin.html  Linux System Administration Tutorial]&lt;br /&gt;
&lt;br /&gt;
[http://www-uxsup.csx.cam.ac.uk/pub/doc/suse/suse9.0/userguide-9.0/ch24.html Working with the Shell (SUSE Documentation)]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Linux_kernel Linux Kernel]&lt;br /&gt;
&lt;br /&gt;
[http://www.yolinux.com/TUTORIALS/LinuxTutorialAdvanced_vi.html VI Tutorial]&lt;br /&gt;
&lt;br /&gt;
[http://students.cec.wustl.edu/~jg18/guide/ Making the Transition to Linux: A Guide to the Linux Command Line Interface for Students]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 2]]&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Linux&amp;diff=2910</id>
		<title>Linux</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Linux&amp;diff=2910"/>
		<updated>2024-01-23T03:34:37Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Setting File Permissions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[wikipedia:Linux|Linux]] is an [[wikipedia:Free and open-source software|open-source]] operating system based on [[wikipedia:UNIX|UNIX]].  Linux is highly versatile and is used in a wide range of applications.  [[wikipedia:Desktop Linux|Desktop Linux]] is Linux with a GUI (like Microsoft Windows or Mac OS X); Desktop Linux is popular in niche markets, and it is used widely in developing countries.&lt;br /&gt;
&lt;br /&gt;
Linux is the most widely used operating system for web servers.  In CSE330, we will be interacting with Linux from the command line.  This article covers the tools you need to make the best use of Linux.&lt;br /&gt;
&lt;br /&gt;
== Linux Distributions ==&lt;br /&gt;
&lt;br /&gt;
The open-source community is responsible for the development of many different [[wikipedia:Linux distributions|distributions]] of Linux.  Distributions, or ''distros'', are different &amp;quot;flavors&amp;quot; of the Linux operating system with different objectives.&lt;br /&gt;
&lt;br /&gt;
There are hundreds of distributions of Linux.  Three of the main branches are [[wikipedia:Debian|Debian]], [[wikipedia:SuSE|SuSE]] (based on [[wikipedia:Slackware|Slackware]]), and [[wikipedia:Red Hat Enterprise Linux|Red Hat Enterprise Linux (RHEL)]].&lt;br /&gt;
&lt;br /&gt;
For CSE 330, you'll be using a version of Red Hat Enterprise Linux. &lt;br /&gt;
&lt;br /&gt;
=== Red Hat Enterprise Linux (RHEL) ===&lt;br /&gt;
&lt;br /&gt;
Red Hat Enterprise Linux, or '''RHEL''', was first introduced in 1994.  RHEL is known for being a good choice for enterprises that wish to use Linux as their primary OS.  RHEL has an abundance of administration tools.&lt;br /&gt;
&lt;br /&gt;
The Linux Lab in Lopata Hall uses '''[[wikipedia:Fedora Linux|Fedora Linux]]''', a desktop distribution based on RHEL.  '''[[wikipedia:CentOS|CentOS]]''' is a popular RHEL derivative that is widely used in web servers.  The '''[[wikipedia:Amazon Machine Image|Amazon EC2 Linux AMI]]''' is derived from CentOS, making it a distribution in the RHEL family.&lt;br /&gt;
&lt;br /&gt;
=== Special Note: Linux Kernel and Modules ===&lt;br /&gt;
{{XKCD&lt;br /&gt;
|id=619&lt;br /&gt;
|name=supported_features&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
What separates Linux from other Unix variants is its kernel. The kernel is the most important component of the operating system and is responsible for scheduling processes, providing access to the hardware devices, allocating memory to the programs, and so on.&lt;br /&gt;
&lt;br /&gt;
The Linux kernel uses both monolithic and modular approaches. A monolithic kernel is a single program that contains all the code so any addition to kernel (such as code to access a driver) requires recompiling the code. A monolithic kernel is usually a little faster and could have a smaller size since only the absolutely necessary code is there. The modular kernel, on the other hand, enables dynamic loading and unloading  of kernel code, called ''modules''. Typical modules include device drivers. Thanks to this modular approach, Linux seldom requires a reboot after installing a new device.&lt;br /&gt;
&lt;br /&gt;
== Bash ==&lt;br /&gt;
&lt;br /&gt;
In this course, you will be interacting with Linux primarily on the command line.  The most widespread ''command line language'' is '''Bash'''.  This is described in more detail in [[Bash|the Bash guide]].&lt;br /&gt;
&lt;br /&gt;
== Files and Permissions ==&lt;br /&gt;
&lt;br /&gt;
At the core of a Unix-based operating system is a directory structure with files and permissions.&lt;br /&gt;
&lt;br /&gt;
=== Filesystem Hierarchy ===&lt;br /&gt;
&lt;br /&gt;
The root directory of Linux contains a dozen or so subdirectories, each with a specific purpose:&lt;br /&gt;
&lt;br /&gt;
* '''/bin''' contains [[Bash#Running Programs|binaries]] used by all users&lt;br /&gt;
* '''/sbin''' contains system binaries typically used only by the system administrator&lt;br /&gt;
* '''/lib''' contains libraries for the binaries found in '''/bin''' and '''/sbin'''&lt;br /&gt;
* '''/etc''' contains configuration files&lt;br /&gt;
** '''/etc/yum.conf''' Configuration file for yum&lt;br /&gt;
** '''/etc/yum/yum.repos.d''' Directory containing .repo files for online repositories&lt;br /&gt;
** '''/etc/crontab''' System-wide crontab file&lt;br /&gt;
** '''/etc/fstab''' Information about default partitions to be mounted&lt;br /&gt;
** '''/etc/group''' List of groups in the system&lt;br /&gt;
** '''/etc/hosts''' List of IP addresses with their names&lt;br /&gt;
** '''/etc/inittab''' What to do at each run-level&lt;br /&gt;
** '''/etc/inetd.conf''' Configuration file for some internet services (replaced by xinetd.* in most systems)&lt;br /&gt;
** '''/etc/modules.conf''' Module information for the boot&lt;br /&gt;
** '''/etc/motd''' Message to be seen at the login prompt&lt;br /&gt;
** '''/etc/passwd''' User information&lt;br /&gt;
** '''/etc/profile''' System level initial file for sh and its derivatives&lt;br /&gt;
** '''/etc/shadow''' User passwords&lt;br /&gt;
* '''/dev''' contains device files&lt;br /&gt;
* '''/proc''' contains information on currently running processes&lt;br /&gt;
* '''/var''' contains files whose contents is expected to change&lt;br /&gt;
** '''/var/log''' contains system log files&lt;br /&gt;
*** '''/var/log/messages''' System/Kernel messages&lt;br /&gt;
*** '''/var/log/syslog''' System log (mostly for Daemons)&lt;br /&gt;
*** '''/var/log/wtmp'''' User access log (binary)&lt;br /&gt;
*** '''/var/log/dmesg''' Boot-up messages&lt;br /&gt;
*** '''/var/log/auth.log''' Authorization logs&lt;br /&gt;
** '''/var/lib''' contains packages and database files&lt;br /&gt;
** '''/var/spool''' contains print queues&lt;br /&gt;
* '''/tmp''' contains temporary files that are deleted at system reboot&lt;br /&gt;
* '''/usr''' contains user programs&lt;br /&gt;
** '''/usr/bin''' contains binaries for user programs&lt;br /&gt;
** '''/usr/sbin''' contains binaries for system administrators&lt;br /&gt;
** '''/usr/lib''' contains libraries for '''/usr/bin''' and '''/usr/sbin'''&lt;br /&gt;
** '''/usr/local''' contains programs that you install from source&lt;br /&gt;
* '''/home''' contains users' home directories&lt;br /&gt;
* '''/root''' is root's home directory&lt;br /&gt;
* '''/boot''' contains boot loader files (do not touch unless you know what you are doing!)&lt;br /&gt;
* '''/opt''' contains optional add-on applications&lt;br /&gt;
* '''/mnt''' is where system administrators can mount filesystems&lt;br /&gt;
* '''/media''' contains links to removable media devices (for example, CDs)&lt;br /&gt;
* '''/srv''' contains site-specific data which are served by the system&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For more information, see the Wikipedia article on the [[wikipedia:Filesystem Hierarchy Standard|Filesystem Hierarchy Standard]].&lt;br /&gt;
&lt;br /&gt;
=== File Permissions ===&lt;br /&gt;
&lt;br /&gt;
Every file in Linux has permissions that define which users can Read, Write, and Execute it.  Every file has an owner and a group.  The permissions for a file are set on three levels: User (owner), Group, and Other.&lt;br /&gt;
&lt;br /&gt;
==== Symbolic Notation ====&lt;br /&gt;
&lt;br /&gt;
When you view the permissions of a file in Linux, they will most often be displayed in ''symbolic notation''.  Symbolic notation consists of 10 characters: the first defines the file type, and then there are three characters each for User, Group, and Other permissions.&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;-r--r--r--&amp;lt;/code&amp;gt; is a normal file that is readable by all users but writable or executable by no one.&lt;br /&gt;
* &amp;lt;code&amp;gt;-rwxr-xr-x&amp;lt;/code&amp;gt; is a normal file that is readable and executable by everyone but only writable by User (the file's owner).  This is the most common permission set.&lt;br /&gt;
&lt;br /&gt;
==== Viewing File Permissions ====&lt;br /&gt;
&lt;br /&gt;
To view the permissions of all files in a certain directory, run the binary &amp;lt;code&amp;gt;ls -l&amp;lt;/code&amp;gt; in Bash:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ls -l   # displays a list of all files in a directory with their permissions in symbolic notation&lt;br /&gt;
total 16&lt;br /&gt;
lrwxr-xr-x  1 sffc  wheel   6 Aug  9 09:13 link -&amp;gt; myfile.txt&lt;br /&gt;
-rwxr--r--  1 sffc  wheel  12 Aug  9 09:13 myfile.txt&lt;br /&gt;
$ ls -l myfile.txt   # displays the permissions of only myfile.txt&lt;br /&gt;
-rwxr--r--  1 sffc  wheel  12 Aug  9 09:13 myfile.txt&lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Setting File Permissions ====&lt;br /&gt;
&lt;br /&gt;
Linux comes with several useful binaries for setting file permissions.&lt;br /&gt;
&lt;br /&gt;
* '''chmod''' is used for setting permissions&lt;br /&gt;
* '''chown''' is used for setting a file's owner&lt;br /&gt;
* '''chgrp''' is used for setting a file's group&lt;br /&gt;
&lt;br /&gt;
Some examples are shown below.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ chmod a+x myfile.txt   # turns on the Execute option for all users&lt;br /&gt;
$ chmod o-w myfile.txt   # turns off the Write option for Other users&lt;br /&gt;
$ chmod u+wx-r myfile.txt   # turns on the Write and Execute options for User (the file's owner) and also turns off the Read option for User&lt;br /&gt;
$ chown todd myfile.txt   # sets the owner of myfile.txt to the user todd.  Note: First comes the user, then comes the filename: not the other way around!&lt;br /&gt;
$ chgrp staff myfile.txt   # sets the group of myfile.txt to usergroup staff&lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information, see https://www.linux.com/training-tutorials/how-manage-file-and-folder-permissions-linux/&lt;br /&gt;
&lt;br /&gt;
=== The . and .. Directories ===&lt;br /&gt;
&lt;br /&gt;
The '''.''' directory is a reference to the current directory.   The '''..''' directory brings you one level up in the filesystem.&lt;br /&gt;
&lt;br /&gt;
=== Symbolic Links ===&lt;br /&gt;
&lt;br /&gt;
A [[wikipedia:Symbolic link|symbolic link]], or ''symlink'', is basically a link from one spot in the filesystem to another.  You can think of them like ''aliases'' in Mac OS X.  To create a a symlink, use the ''ln -s'' command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ln -s /path/to/file.txt /path/to/link   # creates a symlink to file.txt at /path/to/link&lt;br /&gt;
&lt;br /&gt;
# Example:&lt;br /&gt;
$ ln -s /home/todd/instructions.doc /var/www/public_html/classes/instructions.doc   # creates a symlink in the web server to instructions.doc&lt;br /&gt;
$ vi /var/www/public_html/classes/instructions.doc   # changes to the symbolic link will be reflected in the original file&lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== User Management ==&lt;br /&gt;
&lt;br /&gt;
=== Adding a New User ===&lt;br /&gt;
&lt;br /&gt;
To create a new user, use the '''useradd''' command.  Then, set a password for that user using the '''passwd''' command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo useradd -r -m -c &amp;quot;&amp;lt;My Full Name&amp;gt;&amp;quot; &amp;lt;myUserName&amp;gt;&lt;br /&gt;
$ sudo passwd &amp;lt;myUserName&amp;gt;&lt;br /&gt;
Enter new UNIX password: &lt;br /&gt;
Retype new UNIX password: &lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' If Linux doesn't like your command, first check your syntax and then try it with single quotes around your full name and password instead of double quotes. If this works it is likely that you used some special characters in your password such as '!', which serves a special purpose in the shell. This is because Linux takes parameters enclosed in double quotes as one string, but still looks for special characters inside of the string and acts in accordance with their normal meaning. On the other hand, single quotes tell the shell to ignore any special characters within.&lt;br /&gt;
&lt;br /&gt;
=== Adding a User to the Sudoers List ===&lt;br /&gt;
&lt;br /&gt;
For security reasons, you should never SSH into your server as the root user.  Instead, you should use a normal user to whom you give '''sudo''' privileges.  (For more detail on sudo, see [[Linux#SUDO|the Linux guide]].)&lt;br /&gt;
&lt;br /&gt;
To give a user sudo privileges, use the command '''visudo''', which opens up the SUDO configuration file in the system's default text editor.  (Never edit the file ''/etc/sudoers'' directly!)  SUDO users are specified using lines similar to&lt;br /&gt;
&lt;br /&gt;
 alice   ALL=(ALL) ALL&lt;br /&gt;
&lt;br /&gt;
Add that line immediately below  the line defining '''root''':&lt;br /&gt;
&lt;br /&gt;
 root   ALL=(ALL) ALL&lt;br /&gt;
&lt;br /&gt;
When you are finished, save and close the file.  For more information on editing files on the command line, refer to [[#File Editors|the section about File Editors in this guide]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- AS of 02/19/2017, this link isn't available in HTTPS. --&amp;gt;&lt;br /&gt;
In this case, '''alice''' will be able to run any command with SUDO privileges on the computer.   For more detail on SUDO configuration, see http://www.linuxhelp.net/guides/sudo/&lt;br /&gt;
&lt;br /&gt;
'''Note:''' The visudo utility is especially useful because it not only locks the sudoers file against simultaneous edits, but it also checks the file for syntax errors when you quit. Therefore, it is always recommended that you use visudo to change the sudoers list rather than attempting to modify it directly.&lt;br /&gt;
&lt;br /&gt;
== Networking ==&lt;br /&gt;
&lt;br /&gt;
In Linux, you can see your network information by typing '''ifconfig'''. This command shows the status information of each network interface, including the IP address you will need to remotely connect to your instance. The interface ''lo'' is the special loopback interface with IP address 127.0.0.1.  This refers to your local machine and any connection from your machine to your machine goes through this pseudo-interface.  Typical network interfaces include ''eth0'', ''eth1'',..., ''wlan0'', etc. Ethernet cards are represented with ''ethX''.  In the past, most wireless cards showed up as ''wlanX'', but it is also common now for them to be represented with ''ethX'' names. ''ifconfig'' also gives information such as hardware address (MAC), netmask, and broadcast addresses.&lt;br /&gt;
&lt;br /&gt;
You can start or stop networking by calling ''/etc/init.d/networking'' script. As with most ''/etc/init.d'' scripts, this script takes several options, such as ''start'', ''stop'', ''restart''.  Note even if you stop networking, you would still have your lo interface. You can look at the code of the script to find out what it actually does. You can also stop or start individual interfaces by using the '''ifup''' and '''ifdown''' commands.&lt;br /&gt;
&lt;br /&gt;
The network configuration files are stored in ''/etc/network''. ''/etc/network/interfaces'' contains the defaults for each interface. For xample, you could specify static IP, netmask, network, broadcast and default gateway for an interface here, but you should not need to edit this files in general.  These default options can be changed with the '''ifconfig''' command. The ''/etc/network/if-down.d'' and ''/etc/network/if-up.d'' directories contain the scripts that are going to be executed when an interface is turned on or off.  Of course, most modern Linux distributions have GUI tools for doing network configuration more easily, and you shouldn't need to change anything for the purposes of this course.&lt;br /&gt;
&lt;br /&gt;
== Synchronizing Date and Time ==&lt;br /&gt;
&lt;br /&gt;
In order to avoid setting your system's time manually at every daylight savings change, you can use a Network Time Server via the Network Time Protocol (NTP).&lt;br /&gt;
&lt;br /&gt;
The NTP Daemon comes pre-installed on EC2 AMI instances.&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
=== Setting Timezone ===&lt;br /&gt;
&lt;br /&gt;
Your server is probably not set to the correct timezone by default.&lt;br /&gt;
&lt;br /&gt;
The timezone files are in the directory ''/usr/share/zoneinfo''. They are further organized within subdirectories grouped by region.  For instance, Rome's time zone file is stored within ''/usr/share/zoneinfo/Europe''.&lt;br /&gt;
&lt;br /&gt;
In order to set the time zone, simply copy the desired time zone file to our ''/etc'' directory as a new file named &amp;quot;localtime&amp;quot;.  For example, to set the the machine's system time to Rome's time zone, we would enter the command&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo cp /usr/share/zoneinfo/Europe/Rome /etc/localtime&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''ntp'' uses ''/etc/ntp.conf'' configuration file to find the ostnames of remote time servers.  The defaults here are probably fine.&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Installing Software ==&lt;br /&gt;
&lt;br /&gt;
The package management tool in Red Hat Enterprise Linux (and therefore also your Amazon EC2 instance) is '''rpm'''.   If you have an ''rpm'' package, you can install it by&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ rpm -i somepackage.rpm&lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This requires that ''somepackage.rpm'' be in your current directory, which means you will have to download the file yourself (or create it). It requires you to manually install any dependencies the package has.&lt;br /&gt;
&lt;br /&gt;
=== Repository-Based Package Managers ===&lt;br /&gt;
&lt;br /&gt;
A better alternative is to use a repository-based package manager.  In RHEL, this is '''yum'''.&lt;br /&gt;
&lt;br /&gt;
Before you install new software, you need to ensure that your local list of available packages is up-to-date.  Run the following commands to perform this operation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;gt;&lt;br /&gt;
yum check-update&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After you have ensured that your package list is synced with the remote repository, you can start installing packages.  To install a package, the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;gt;&lt;br /&gt;
yum install &amp;lt;package-name&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get a permission denied error, try sudoing the command, like '''sudo apt-get install &amp;lt;xxxx&amp;gt;'''&lt;br /&gt;
&lt;br /&gt;
For example, this is how you would install ''lynx'', a command-line web browser, in your RHEL Linux distribution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ lynx --version   # is lynx installed?&lt;br /&gt;
-bash: lynx: command not found&lt;br /&gt;
$ sudo yum check-update   # sync package lists with the remote repositories&lt;br /&gt;
$ sudo yum install lynx    # install the lynx package&lt;br /&gt;
Downloading Packages:&lt;br /&gt;
lynx-2.8.6-27.6.amzn1.i686.rpm        | 1.8 MB     00:00     &lt;br /&gt;
Running rpm_check_debug&lt;br /&gt;
Running Transaction Test&lt;br /&gt;
Transaction Test Succeeded&lt;br /&gt;
Running Transaction&lt;br /&gt;
  Installing : lynx-2.8.6-27.6.amzn1.i686             1/1 &lt;br /&gt;
&lt;br /&gt;
Installed:&lt;br /&gt;
  lynx.i686 0:2.8.6-27.6.amzn1                                                                                                                                                                                                                &lt;br /&gt;
&lt;br /&gt;
Complete!&lt;br /&gt;
$ lynx --version   # test again to see if we have lynx installed&lt;br /&gt;
Lynx Version 2.8.6rel.5 (09 May 2007)&lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also search for available packages by name or by the name of a file that they install.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ yum search lynx   # search for packages whose name contains lynx&lt;br /&gt;
======= N/S Matched: lynx =======&lt;br /&gt;
lynx.i686 : A text-based Web browser&lt;br /&gt;
$ yum provides lynx   # search for packages that install a file or command named lynx&lt;br /&gt;
lynx-2.8.6-27.6.amzn1.i686 : A text-based Web browser&lt;br /&gt;
Repo        : installed&lt;br /&gt;
Matched from:&lt;br /&gt;
Other       : Provides-match: lynx&lt;br /&gt;
$ &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The list of repositories that '''yum''' searches is located at &amp;lt;code&amp;gt;/etc/yum.conf&amp;lt;/code&amp;gt;.  The list of repositories that '''apt''' searches is located at &amp;lt;code&amp;gt;/etc/apt/sources.list&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
=== Essential Packages ===&lt;br /&gt;
&lt;br /&gt;
To save you some headaches later on, it is recommended that you install a few essential package bundles when you first create a new Linux instance.  These packages include things like Make and a C compiler.&lt;br /&gt;
&lt;br /&gt;
'''RHEL:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo yum groupinstall &amp;quot;Development Tools&amp;quot;&lt;br /&gt;
$ sudo yum install kernel-devel kernel-headers&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Searching for Packages ===&lt;br /&gt;
&lt;br /&gt;
You can search for packages by name, command, and so on.  For example, to search for all packages relating to &amp;quot;lynx&amp;quot;, you could do:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''RHEL:'''&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ yum search lynx&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Command Reference ==&lt;br /&gt;
Earlier, you saw that '''cat''' is a command that shows the contents of a file.  Below is a list of other useful commands in Linux.&lt;br /&gt;
&lt;br /&gt;
=== Navigation and File Management ===&lt;br /&gt;
&lt;br /&gt;
* '''ls''' List file(s) in current working directory&lt;br /&gt;
** '''ll''' Shortcut to '''ls -l'''.  List files with more details than '''ls'''.  Only available in certain distributions&lt;br /&gt;
* '''cd''' Change working directory.  Note: cd called without any arguments moves you to your home directory&lt;br /&gt;
* '''cp''' Copy a file&lt;br /&gt;
* '''mv''' Move or rename a file&lt;br /&gt;
* '''rm''' Remove a file&lt;br /&gt;
** '''rm -r''' Remove a directory and all files in it&lt;br /&gt;
* '''ln -s''' Create a symlink to a file&lt;br /&gt;
* '''mkdir''' Create a directory&lt;br /&gt;
* '''rmdir''' Remove a directory (directory must be empty; if it's not, use '''rm -r''')&lt;br /&gt;
* '''cat''' Display the contents of a file&lt;br /&gt;
* '''less''' Display the contents of a file, wait for the user at each page&lt;br /&gt;
* '''tail''' Display the last 20 lines of a file&lt;br /&gt;
** '''tail -f''' Display the last 20 lines of a file and then wait for changes, displaying them as they occur.  Useful for monitoring log files.&lt;br /&gt;
* '''chown''' Change the owner of a file&lt;br /&gt;
* '''chgrp''' Change the group of a file&lt;br /&gt;
* '''chmod''' Change the security permissions of a file&lt;br /&gt;
* '''grep''' Display the lines of a file matching a user specified string&lt;br /&gt;
* '''diff''' Display the difference between two files&lt;br /&gt;
&lt;br /&gt;
=== System Administration ===&lt;br /&gt;
&lt;br /&gt;
* '''df''' Display free diskspace&lt;br /&gt;
* '''du''' Display disk usage&lt;br /&gt;
* '''free''' Display memory usage information&lt;br /&gt;
* '''date''' Display current time and date&lt;br /&gt;
* '''top''' Display the CPU and Memory usages of current processes&lt;br /&gt;
* '''ps''' Display current processes&lt;br /&gt;
* '''kill''' Terminate a running process&lt;br /&gt;
* '''killall''' Terminate the running process matching user specified criterias&lt;br /&gt;
* '''ping hostname''' Ping a host&lt;br /&gt;
* '''host''' Get the IP address of a host&lt;br /&gt;
* '''passwd''' Change the user password&lt;br /&gt;
* '''su user''' Switch to the privileges of another user&lt;br /&gt;
* '''shutdown''' Power off the computer&lt;br /&gt;
* '''reboot''' Reboot the computer&lt;br /&gt;
* '''clear''' Clear the terminal&lt;br /&gt;
* '''ifconfig''' Display/Configure a network device&lt;br /&gt;
* '''file''' Show the file type&lt;br /&gt;
* '''lsmod''' Display loaded kernel modules&lt;br /&gt;
* '''insmod''' Install a kernel module&lt;br /&gt;
* '''modprobe''' Load a kernel module (also load the dependencies)&lt;br /&gt;
* '''adduser''' Add a new user&lt;br /&gt;
* '''exit''' Exit from a shell&lt;br /&gt;
* '''lpr''' Print a file&lt;br /&gt;
* '''head''' Display  lines at the beginning of a file&lt;br /&gt;
* '''tail''' Display lines at the end of a file&lt;br /&gt;
* '''pwd''' Display the name of the current working directory&lt;br /&gt;
* '''lsof''' Open files in the system&lt;br /&gt;
* '''netstat''' Statistics related to open sockets&lt;br /&gt;
* '''vmstat''' Reports information about processes, memory, IO, and CPU&lt;br /&gt;
&lt;br /&gt;
=== File Editors ===&lt;br /&gt;
{{XKCD&lt;br /&gt;
|name=real_programmers&lt;br /&gt;
|id=378&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
It is sometimes convenient to edit files using the command line.  Three widely-used command line text editors are '''vi''', '''emacs''', and '''nano'''.&lt;br /&gt;
&lt;br /&gt;
==== Vi ====&lt;br /&gt;
&lt;br /&gt;
To edit a file using Vi, use the command '''vi'''.  You will see something like this:&lt;br /&gt;
&lt;br /&gt;
 .&lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 &amp;quot;myfile.txt&amp;quot; [New File]&lt;br /&gt;
&lt;br /&gt;
To insert text into the file, press '''i''' once, then type away:&lt;br /&gt;
&lt;br /&gt;
 Hello World&lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 -- INSERT -- &lt;br /&gt;
&lt;br /&gt;
To leave insert mode, press ESC.&lt;br /&gt;
&lt;br /&gt;
To save your file, type the command ''':w''' and press Enter.&lt;br /&gt;
&lt;br /&gt;
 Hello World&lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 ~                                                     &lt;br /&gt;
 &amp;quot;myfile.txt&amp;quot; [New] 1L, 12C written&lt;br /&gt;
&lt;br /&gt;
To save and then close your file, type the command ''':wq'''.  (To close the file without saving, use the command ''':q!''')&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For more vi commands, see https://ss64.com/vi.html&lt;br /&gt;
&lt;br /&gt;
==== Emacs ====&lt;br /&gt;
&lt;br /&gt;
To edit a file using emacs, use the command '''emacs'''.  You can start typing immediately:&lt;br /&gt;
&lt;br /&gt;
 Hello World&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 -uuu:**-F1  myfile.txt     All L1     (Text)----------&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
To save a file, type '''C-x C-s''' (that means Control-X, then Control-S):&lt;br /&gt;
&lt;br /&gt;
 Hello World&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 -uuu:---F1  myfile.txt     All L1     (Text)----------&lt;br /&gt;
 Wrote /home/todd/myfile.txt&lt;br /&gt;
&lt;br /&gt;
To quit emacs, type '''C-x C-c'''.  (It will ask you whether or not to save the file if you've made changes.)&lt;br /&gt;
&lt;br /&gt;
For more emacs commands, see http://souptonuts.sourceforge.net/chirico/emacs_ref.html&lt;br /&gt;
&lt;br /&gt;
==== Nano ====&lt;br /&gt;
&lt;br /&gt;
To edit a file using nano, use the command '''nano'''.  You can start editing the file immediately:&lt;br /&gt;
&lt;br /&gt;
   GNU nano 2.0.6               File: myfile.txt                                      &lt;br /&gt;
 &lt;br /&gt;
 Hello World&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
 ^G Get Help   ^O WriteOut   ^R Read File  ^Y Prev Page  ^K Cut Text   ^C Cur Pos&lt;br /&gt;
 ^X Exit       ^J Justify    ^W Where Is   ^V Next Page  ^U UnCut Text ^T To Spell&lt;br /&gt;
&lt;br /&gt;
Nano tells you the commands you need right there so you don't have to always keep looking them up like with Vi and Emacs.&lt;br /&gt;
&lt;br /&gt;
For more detail on Nano commands, see http://www.nano-editor.org/dist/v2.2/nano.html&lt;br /&gt;
&lt;br /&gt;
== Linux Resources ==&lt;br /&gt;
&lt;br /&gt;
[http://www.yolinux.com/TUTORIALS/LinuxTutorialSysAdmin.html  Linux System Administration Tutorial]&lt;br /&gt;
&lt;br /&gt;
[http://www-uxsup.csx.cam.ac.uk/pub/doc/suse/suse9.0/userguide-9.0/ch24.html Working with the Shell (SUSE Documentation)]&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Linux_kernel Linux Kernel]&lt;br /&gt;
&lt;br /&gt;
[http://www.yolinux.com/TUTORIALS/LinuxTutorialAdvanced_vi.html VI Tutorial]&lt;br /&gt;
&lt;br /&gt;
[http://students.cec.wustl.edu/~jg18/guide/ Making the Transition to Linux: A Guide to the Linux Command Line Interface for Students]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 2]]&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_2&amp;diff=2909</id>
		<title>Module 2</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_2&amp;diff=2909"/>
		<updated>2024-01-22T22:30:05Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Calculator */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
Module 2 introduces you to Linux, a command-line environment, the Apache web server, and PHP.  You will create and configure your own cloud instance, install Apache and related software, and then form groups to make a simple file sharing site.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:1.3em; line-height:1.2em; color:blue;&amp;quot;&amp;gt;'''DO NOT WAIT UNTIL THE LAST MINUTE TO START ON THIS (or any) MODULE!'''  The most common reason students perform poorly in this class is procrastination.  You have been warned.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using the Wiki ==&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
Text enclosed by &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;&amp;lt;&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;&amp;gt;&amp;lt;/syntaxhighlight&amp;gt; should be replaced by content unique to you.&lt;br /&gt;
&lt;br /&gt;
'''Example'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo useradd -r -m -c &amp;quot;&amp;lt;My Full Name&amp;gt;&amp;quot; &amp;lt;usernameHere&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
becomes&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo useradd -r -m -c &amp;quot;Zach Cohn&amp;quot; zcohn&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Reading ==&lt;br /&gt;
&lt;br /&gt;
The following articles on the online class wiki textbook contain information that will help you complete the assignments.&lt;br /&gt;
&lt;br /&gt;
* [[Linux]]&lt;br /&gt;
* [[Bash]]&lt;br /&gt;
* [[Amazon Web Services]]&lt;br /&gt;
* [[SSH]]&lt;br /&gt;
* [[Apache]]&lt;br /&gt;
* [[PHP]]&lt;br /&gt;
* [[Workflow]]&lt;br /&gt;
* [[VS Code]]&lt;br /&gt;
* [[Web Application Security, Part 1]]&lt;br /&gt;
* [[FAQ - Mod 2]]&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;There are a lot of wiki pages that you need to read in order to complete the individual portion of Module 2.  The wiki pages contain an assortment of required steps, optional steps, and information.  To make things easier, we have highlighted the ''required steps'' with a red bar, like you see on the left of this message.  Do not skip anything marked with a red bar, or else you will not have a perfectly configured instance.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Learn About Linux ===&lt;br /&gt;
&lt;br /&gt;
Linux is an open-source operating system based on UNIX. Linux is highly versatile and is used in a wide range of applications.&lt;br /&gt;
&lt;br /&gt;
If you are not a Linux guru, read the Linux guide to get started: [[Linux]]&lt;br /&gt;
&lt;br /&gt;
=== Windows Users Only: Enable Windows Subsystem for Linux (WSL) or Install Cygwin ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You will need WSL or Cygwin in order to log into and configure your EC2 instance. Cygwin is already installed on the CEC machines. If you're using Windows 10, you can use WSL, which is an officially-supported way of accessing a Linux terminal on Windows. If not, you'll have to use Cygwin. Instructions for installing either on your personal machine are located in [[Workflow#Cygwin|the Workflow guide]].&lt;br /&gt;
&lt;br /&gt;
Mac OS X users should located the &amp;quot;Terminal&amp;quot; application, which is installed by default; you will need this in the coming steps.&lt;br /&gt;
&lt;br /&gt;
=== Create an AWS EC2 Instance ===&lt;br /&gt;
&lt;br /&gt;
Once you understand [[Linux]], you need to set up your Amazon EC2 Instance.  Use the AWS article to guide you through the process: [[Amazon Web Services]]&lt;br /&gt;
&lt;br /&gt;
=== Configure SSH ===&lt;br /&gt;
&lt;br /&gt;
Follow the instructions in [[SSH#SSH Configuration|the SSH guide]] to do the following:&lt;br /&gt;
&lt;br /&gt;
# Create your own SSH key pair&lt;br /&gt;
# Log in as the default user to your EC2 instance&lt;br /&gt;
# Create a new user&lt;br /&gt;
# Give the new user your SSH public key&lt;br /&gt;
&lt;br /&gt;
From now on, when you need to log into your EC2 instance as an administrator, just pop up a terminal and run:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ ssh &amp;lt;your-instance-username&amp;gt;@&amp;lt;ec2-xx-xx-xx-xx.compute-1.amazonaws.com&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To save from typing this command in every time you want to access your server, you can set an '''alias''' in your terminal.&lt;br /&gt;
&lt;br /&gt;
In the '''Mac''' terminal, vim ~/.zshrc and input the following command:&lt;br /&gt;
 $ alias aws='ssh &amp;lt;your-instance-username&amp;gt;@&amp;lt;ec2-xx-xx-xx-xx.compute-1.amazonaws.com&amp;gt;'&lt;br /&gt;
Now, whenever you type aws in your terminal, it will type your ssh command.&lt;br /&gt;
&lt;br /&gt;
In '''Cygwin''', vim ~/.bash_profile and input the following:&lt;br /&gt;
 export aws=&amp;quot;ssh &amp;lt;your-instance-username&amp;gt;@&amp;lt;ec2-xx-xx-xx-xx.compute-1.amazonaws.com&amp;gt;&amp;quot;&lt;br /&gt;
And you run this command by typing '''$aws'''&lt;br /&gt;
Also note that you may have to restart your terminal for this to take effect, or put the command in your ~/.bashrc file&lt;br /&gt;
&lt;br /&gt;
=== Install Essential Packages ===&lt;br /&gt;
&lt;br /&gt;
Recall that software installation in Linux instances is usually handled through a package manager, like '''yum'''.  For more information, refer to [[Linux#Repository-Based Package Managers|the Linux guide]].&lt;br /&gt;
&lt;br /&gt;
To make sure everything is working properly, '''install your first package(s) according to the ''Essential Packages'' subsection in the Linux guide.'''&lt;br /&gt;
&lt;br /&gt;
=== Set the Timezone ===&lt;br /&gt;
&lt;br /&gt;
'''Set your server to use US Central time (America/Chicago).'''  Instructions are in the Linux guide: [[Linux#Synchronizing Date and Time]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up the Apache Web Server ===&lt;br /&gt;
&lt;br /&gt;
You need to '''install the Apache web server on your EC2 instance'''.  Refer to [[Apache|the Apache guide]].&lt;br /&gt;
&lt;br /&gt;
In order for your web server to be accessible, you need to '''open up Port 80 on your EC2 instance'''.  Instructions are in the AWS guide: [[Amazon Web Services#Enabling Web Access to your EC2 Instance]]&lt;br /&gt;
&lt;br /&gt;
'''Enable the UserDir module in Apache.'''  Instructions are in the Apache guide: [[Apache#The UserDir Module]]&lt;br /&gt;
&lt;br /&gt;
=== Install PHP ===&lt;br /&gt;
&lt;br /&gt;
You need to '''install PHP on your EC2 server'''.  Instructions are at the top of the PHP guide: [[PHP]]&lt;br /&gt;
&lt;br /&gt;
You need to '''configure PHP to show errors'''.  Instructions are immediately below installation in the PHP guide.&lt;br /&gt;
&lt;br /&gt;
=== Learn about the PHP Language ===&lt;br /&gt;
&lt;br /&gt;
Before you can continue, you will need to make yourself acquainted with PHP language components.  Read the PHP guide for an overview: [[PHP#PHP Language Components]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up your Workspace ===&lt;br /&gt;
&lt;br /&gt;
You are now ready to set up the workspace that you will be using for the rest of the semester.  Follow the instructions in [[Workflow]] to:&lt;br /&gt;
&lt;br /&gt;
# Make an account on GitHub&lt;br /&gt;
# Setup a repo using GitHub Classroom&lt;br /&gt;
# Clone your CSE 330 repo from GitHub&lt;br /&gt;
# Install a text editor such as '''VSCode''' to write your assignments with&lt;br /&gt;
# Either install an FTP client, or use SFTP through command line, to transfer files from your local machine to your instance&lt;br /&gt;
&lt;br /&gt;
=== Calculator ===&lt;br /&gt;
&lt;br /&gt;
'''Make a calculator using PHP and an HTML form.'''  The form should have two number inputs.  The form should submit a GET request either back to the same page or to a different results page.  The calculator should support addition, subtraction, multiplication, and division by means of a radio button group on the page.  (Consider edge cases!)&lt;br /&gt;
&lt;br /&gt;
=== Git Tutorial ===&lt;br /&gt;
&lt;br /&gt;
Complete all of the levels of the Main and Remote sections of [https://learngitbranching.js.org/ this Git tutorial]. After you finish the tutorial, take two screenshots showing the completion of all of the levels of the Main and Remote sections. Place these two screenshots in your Module 2 Individual repo.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs (that means you and one other person) on this project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:1.3em; line-height:1.2em; color:blue;&amp;quot;&amp;gt;In this module, and all future modules, the group portion builds off of material you learn in the individual portion.  You should therefore complete the individual portions prior to working on the group portions.  (Trust us: it will make your life easier!)&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple File Sharing Site ===&lt;br /&gt;
&lt;br /&gt;
You will be making a simple file sharing site that supports uploading, viewing, and deleting files associated with various users.  Details:&lt;br /&gt;
&lt;br /&gt;
* You should have a file named '''users.txt''' stored in a secure place on your filesystem.  It should have at least three usernames, with one username per line.&lt;br /&gt;
*: Passwords add an extra layer of complexity (encryption) that we will cover in Module 3.  You will not earn credit for implementing passwords as your creative portion for this module.&lt;br /&gt;
* Users of the file sharing site should be able to enter their username and then log in.&lt;br /&gt;
*: You may implement logins using session variables, or you may implement them using a GET parameter that is passed between pages.  You will need to always use sessions starting in Module 3.&lt;br /&gt;
* Users should see a list of all files associated with their username after the log in.&lt;br /&gt;
* Users should be able to view, upload, and delete files associated with their username.&lt;br /&gt;
* The URI should NOT reveal the internal file structure of your web site.&lt;br /&gt;
** Example of what not to do:  http://www.example.com/download.php?file=/home/paul/file.txt&lt;br /&gt;
** Another bad example:  http://www.example.com/~user/file.txt&lt;br /&gt;
** Good example: http://www.example.com/view.php?user=music&amp;amp;name=file.txt&lt;br /&gt;
*: In general, don't reveal any internal information about the site.&lt;br /&gt;
*: '''Food for thought:''' Given that Apache processes (with the exception of the main process) do not run as root, but rather as the user apache, how can you allow both your user account and the php scripts to read and write the &lt;br /&gt;
*:necessary files?&lt;br /&gt;
*:: ''Hint:'' You shouldn't be storing the user-uploaded files in public_html (that is only the place for your own web-page files), &lt;br /&gt;
*::''Hint number 2:''  you will need to use chown to change permissions to let user apache have permissions on the user-files (that '''are not''' in the public_html folder). If you don't know what this does or how to do this, look at the [[Apache]] page&lt;br /&gt;
* You should customize your file sharing site by implementing an additional feature or two as part of the '''creative portion'''.&lt;br /&gt;
&lt;br /&gt;
You will probably find the PHP guide on this wiki to be helpful: [[PHP#Other PHP Tips]]&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 1]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to follow the conventions of FIEO (Filter Input and Escape Output)'''.  Things you should filter include file names, usernames, and so on.&lt;br /&gt;
* '''Your project must pass the W3C Validator with no errors or warnings'''.  For more information, see the HTML and CSS guide: [[HTML and CSS#Validation]]&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
We will be grading the following aspects of your work.  There are 120 points total. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Assignments (including code) must be committed to GitHub by the end of class on the due date. Commit early and often. Failing to commit by the end of class on the due date will result in a 0. &lt;br /&gt;
&lt;br /&gt;
_____________&lt;br /&gt;
&lt;br /&gt;
# '''Cloud Instance and Web Server (30 Points):'''&lt;br /&gt;
#* You can SSH into your instance using your own custom username and SSH key. Put a screenshot in your repository of your terminal SSH-ing into your instance (15 points)&lt;br /&gt;
#* Your custom username is able to perform SUDO commands. Put a screenshot in your repository of you successfully executing a command with sudo (5 points)&lt;br /&gt;
#* The time zone is correct on your instance. Put a screenshot in your repository of the results of the `date` command (5 points)&lt;br /&gt;
#* The UserDir Apache module is working. Place a file in /home/&amp;lt;username&amp;gt;/public_html and link to the file in your README.md (5 points)&lt;br /&gt;
# '''PHP Calculator (15 Points):'''&lt;br /&gt;
#* The calculator is able to perform all four functions with floating point numbers (2 points each, 8 points in total)&lt;br /&gt;
#* Each function is given as a radio button choice (4 points)&lt;br /&gt;
#* The calculator page passes the W3C HTML validator (3 points)&lt;br /&gt;
#* '''''Make sure you have a README.md file in your individual repo with the link to your calculator on your instance.''''' See the Creative Portion section for more information about .md files.&lt;br /&gt;
# '''Git Tutorial (20 Points):'''&lt;br /&gt;
#* Two screenshots showing the completion of all of the levels of the Main and Remote sections placed in your individual assignment repository.&lt;br /&gt;
# '''File Sharing Site (40 Points):'''&lt;br /&gt;
#* '''''File Management (25 Points):'''''&lt;br /&gt;
#** Users should not be able to see any files until they enter a username and log in (4 points)&lt;br /&gt;
#**: ''Remember that users.txt should be stored in a secure location on your filesystem.  That is, '''you should not be able to type any URL into your browser and see the raw users.txt file!'''''&lt;br /&gt;
#** Users can see a list of all files they have uploaded (4 points)&lt;br /&gt;
#** Users can open files they have previously uploaded (5 points)&lt;br /&gt;
#**: ''Note: Users should be able to open not only plain text files but also other file formats: images, spreadsheets, etc.''&lt;br /&gt;
#** Users can upload files (4 points)&lt;br /&gt;
#**: ''Note: Like users.txt, uploaded files should be stored in a secure location on your filesystem.  That is, '''do not keep your uploads directory underneath a directory served by Apache!'''''&lt;br /&gt;
#** Users can delete files.  If a file is &amp;quot;deleted&amp;quot;, it should actually be removed from the filesystem (4 points)&lt;br /&gt;
#** The directory structure is hidden. Users should not be able to access or view files by manipulating a URL. (2 points)&lt;br /&gt;
#** Users can log out (2 points)&lt;br /&gt;
#**: ''Note: If using session variables, you must ''actually'' log out the user by destroying their session; i.e., don't just redirect them to the login screen.''&lt;br /&gt;
#* '''''Best Practices (10 Points):'''''&lt;br /&gt;
#** Code is well formatted and easy to read, with proper commenting (4 points)&lt;br /&gt;
#** The site follows the FIEO philosophy (3 points)&lt;br /&gt;
#** All pages pass the W3C validator (3 points)&lt;br /&gt;
#* '''''Usability (5 Points):'''''&lt;br /&gt;
#** Site is intuitive to use and navigate (4 points)&lt;br /&gt;
#** Site is visually appealing (1 point)&lt;br /&gt;
# '''Creative Portion (15 Points)''' (see below)&lt;br /&gt;
#* '''''Make sure you have a README.md file in your group repo with the following:'''''&lt;br /&gt;
#** An .md file is a plain text file called a markdown file  [https://guides.github.com/features/mastering-markdown/ ] .  &lt;br /&gt;
#***The contents of your README.md file are shown on your repo, making it easier for us to grade&lt;br /&gt;
#*** You may style the page with bolding, hyperlings, images, block quotes and lists&lt;br /&gt;
#*** [http://dillinger.io/ This online markdown editor] makes it easy to learn this format  &lt;br /&gt;
#** The link to your file sharing site. '''''We need this to grade your work.'''''&lt;br /&gt;
#** A brief description of what you did for your creative portion&lt;br /&gt;
#** Any additional login details needed for the TA&lt;br /&gt;
&lt;br /&gt;
=== Creative Portion ===&lt;br /&gt;
&lt;br /&gt;
This module and all future modules will require that you invest some time into creating additional features for your group project.  Plan to invest at the very least 60 minutes of your time into the creative portion.  In the above rubric, viewing files is worth five and uploading is worth four. The creative portion is worth fifteen points; it should be a very sizable part of your project.&lt;br /&gt;
&lt;br /&gt;
* The creative portion is an opportunity for you to learn the material of your own interest.&lt;br /&gt;
* You will not earn credit for a creative-portion feature that simply rehashes something you've already done in a previous module.&lt;br /&gt;
&lt;br /&gt;
If you need ideas for a creative portion, or if you want to know whether or not your creative portion idea is &amp;quot;hard enough&amp;quot;, ask a TA.&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 2]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=PHP_and_MySQL&amp;diff=2904</id>
		<title>PHP and MySQL</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=PHP_and_MySQL&amp;diff=2904"/>
		<updated>2023-09-26T00:08:58Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Connecting to a MySQL Database in PHP */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;MySQL is great, but it's not useful for web applications without a way to integrate it with your application logic.  This article discusses how to query MySQL from within PHP.&lt;br /&gt;
&lt;br /&gt;
This article assumes that you are comfortable with the content in the following guides.  If you are not, you should read the guides listed below first.&lt;br /&gt;
&lt;br /&gt;
* [[PHP]]&lt;br /&gt;
* [[Introduction to MySQL]]&lt;br /&gt;
* [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{XKCD&lt;br /&gt;
|id=970&lt;br /&gt;
|name=the_important_field&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== PHP Libraries for Database Manipulation ==&lt;br /&gt;
&lt;br /&gt;
PHP comes with many different ways of querying databases.  This guide instructs you on how to use '''MySQL Improved Prepared Statements''', which is a cleaner, more elegant way to perform queries on your database.&lt;br /&gt;
&lt;br /&gt;
== Connecting to a MySQL Database in PHP ==&lt;br /&gt;
&lt;br /&gt;
To connect to a database using the MySQL Improved interface, use the mysqli command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
// Content of database.php&lt;br /&gt;
&lt;br /&gt;
$mysqli = new mysqli('localhost', '&amp;lt;username&amp;gt;', '&amp;lt;password&amp;gt;', '&amp;lt;databasename&amp;gt;');&lt;br /&gt;
&lt;br /&gt;
if($mysqli-&amp;gt;connect_errno) {&lt;br /&gt;
	printf(&amp;quot;Connection Failed: %s\n&amp;quot;, $mysqli-&amp;gt;connect_error);&lt;br /&gt;
	exit;&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to run this code before you can perform ''any'' other query on your database.  Many PHP web developers put this code in a separate file and '''require''' it into other files that require database access.&lt;br /&gt;
&lt;br /&gt;
You should create a new MySQL user with minimal privileges just for PHP to use.&lt;br /&gt;
&lt;br /&gt;
== Performing Queries that Require Parameters ==&lt;br /&gt;
&lt;br /&gt;
When you want to INSERT or UPDATE an entry in your database, you probably need to supply some value from PHP for MySQL to interpret.  This section discusses ''parameter binding'', which is how you can do this sort of thing.&lt;br /&gt;
&lt;br /&gt;
The first type of prepared query we will discuss are INSERT queries.&lt;br /&gt;
&lt;br /&gt;
Suppose you had a form that submitted the following information:&lt;br /&gt;
&lt;br /&gt;
* '''first''', the user's first name&lt;br /&gt;
* '''last''', the user's last name&lt;br /&gt;
* '''dept''', the user's department&lt;br /&gt;
&lt;br /&gt;
You could insert data received from the form into the employees database using the following PHP code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
require 'database.php';&lt;br /&gt;
&lt;br /&gt;
$first = $_POST['first'];&lt;br /&gt;
$last = $_POST['last'];&lt;br /&gt;
$dept = $_POST['dept'];&lt;br /&gt;
&lt;br /&gt;
$stmt = $mysqli-&amp;gt;prepare(&amp;quot;insert into employees (first_name, last_name, department) values (?, ?, ?)&amp;quot;);&lt;br /&gt;
if(!$stmt){&lt;br /&gt;
	printf(&amp;quot;Query Prep Failed: %s\n&amp;quot;, $mysqli-&amp;gt;error);&lt;br /&gt;
	exit;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$stmt-&amp;gt;bind_param('sss', $first, $last, $dept);&lt;br /&gt;
&lt;br /&gt;
$stmt-&amp;gt;execute();&lt;br /&gt;
&lt;br /&gt;
$stmt-&amp;gt;close();&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The query that will end up being executed by the above code is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
insert into employees (first_name, last_name, department) values ('John', 'Deere', 'EECE')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice how the MySQLi interface uses object-oriented PHP.  Refer to [[PHP#Object-Oriented Programming|the PHP guide]] if you need a refresher on object-oriented PHP.&lt;br /&gt;
&lt;br /&gt;
=== bind_param() ===&lt;br /&gt;
&lt;br /&gt;
The most tricky line in the above example is the '''$stmt-&amp;gt;bind_param()''' line.  Here's how it works.&lt;br /&gt;
&lt;br /&gt;
The first parameter defines the data types of data to be inserted into the query.  It is a string with one character per data type.  The possible data types are:&lt;br /&gt;
&lt;br /&gt;
* '''i''' - Integer&lt;br /&gt;
* '''d''' - Decimal&lt;br /&gt;
* '''s''' - String&lt;br /&gt;
* '''b''' - Blob&lt;br /&gt;
&lt;br /&gt;
Note that data types in queries are ''not'' the same as data types in schemas.  For instance, when saving a date into MySQL, you need to use a string representation of the data (except for timestamp, which uses an integer), so you would use the '''s''' option.&lt;br /&gt;
&lt;br /&gt;
The remaining parameters define values associated with each of the question marks in your query.&lt;br /&gt;
&lt;br /&gt;
In the example code in the previous section, there are three question marks in the query, all of which are strings, and so the first argument to '''$stmt-&amp;gt;bind_param()''' is 'sss'.  The remaining three parameters is the information itself to be &amp;quot;injected&amp;quot; into the query.&lt;br /&gt;
&lt;br /&gt;
== Performing Queries that Return Data ==&lt;br /&gt;
&lt;br /&gt;
When you perform a successful SELECT query, MySQL always returns a table with the results of the query.  This section discusses ''result binding'', which is how you can load the result table into PHP.&lt;br /&gt;
&lt;br /&gt;
Consider the following example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
require 'database.php';&lt;br /&gt;
&lt;br /&gt;
$stmt = $mysqli-&amp;gt;prepare(&amp;quot;select first_name, last_name from employees order by last_name&amp;quot;);&lt;br /&gt;
if(!$stmt){&lt;br /&gt;
	printf(&amp;quot;Query Prep Failed: %s\n&amp;quot;, $mysqli-&amp;gt;error);&lt;br /&gt;
	exit;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$stmt-&amp;gt;execute();&lt;br /&gt;
&lt;br /&gt;
$stmt-&amp;gt;bind_result($first, $last);&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;&amp;lt;ul&amp;gt;\n&amp;quot;;&lt;br /&gt;
while($stmt-&amp;gt;fetch()){&lt;br /&gt;
	printf(&amp;quot;\t&amp;lt;li&amp;gt;%s %s&amp;lt;/li&amp;gt;\n&amp;quot;,&lt;br /&gt;
		htmlspecialchars($first),&lt;br /&gt;
		htmlspecialchars($last)&lt;br /&gt;
	);&lt;br /&gt;
}&lt;br /&gt;
echo &amp;quot;&amp;lt;/ul&amp;gt;\n&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
$stmt-&amp;gt;close();&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, we use '''$stmt-&amp;gt;bind_result()''' instead of '''$stmt-&amp;gt;bind_param()''' because we are interested in the output from, not the input to, the query.&lt;br /&gt;
&lt;br /&gt;
=== bind_result() and fetch() ===&lt;br /&gt;
&lt;br /&gt;
Here, our query returns a table with two columns: first_name and last_name.  So, we need to pass two parameters into '''$stmt-&amp;gt;bind_result()''': one to store the first name, and one to store the last name.&lt;br /&gt;
&lt;br /&gt;
After we call '''$stmt-&amp;gt;bind_result()''', we call '''$stmt-&amp;gt;fetch()'''.  '''$stmt-&amp;gt;fetch()''' stores the values from the next row in the result to the variables you specified in '''$stmt-&amp;gt;bind_result()'''.  '''$stmt-&amp;gt;fetch()''' will continue binding rows into the variables until there are no rows left in the result set, at which time it will return null, thereby leaving the ''while'' loop.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Use very unique variable names inside '''$stmt-&amp;gt;bind_result()''', because whatever variables you use will be overwritten.  This includes session variables, which are sometimes linked to the local variable of the same name.&lt;br /&gt;
&lt;br /&gt;
=== get_result() and fetch_assoc() ===&lt;br /&gt;
&lt;br /&gt;
If you do not want to bind the results from your query to variables, there is an alternative option that returns the results in arrays.&lt;br /&gt;
&lt;br /&gt;
Consider this code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
require 'database.php';&lt;br /&gt;
&lt;br /&gt;
$stmt = $mysqli-&amp;gt;prepare(&amp;quot;select first_name, last_name from employees order by last_name&amp;quot;);&lt;br /&gt;
if(!$stmt){&lt;br /&gt;
	printf(&amp;quot;Query Prep Failed: %s\n&amp;quot;, $mysqli-&amp;gt;error);&lt;br /&gt;
	exit;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$stmt-&amp;gt;execute();&lt;br /&gt;
&lt;br /&gt;
$result = $stmt-&amp;gt;get_result();&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;&amp;lt;ul&amp;gt;\n&amp;quot;;&lt;br /&gt;
while($row = $result-&amp;gt;fetch_assoc()){&lt;br /&gt;
	printf(&amp;quot;\t&amp;lt;li&amp;gt;%s %s&amp;lt;/li&amp;gt;\n&amp;quot;,&lt;br /&gt;
		htmlspecialchars( $row[&amp;quot;first_name&amp;quot;] ),&lt;br /&gt;
		htmlspecialchars( $row[&amp;quot;last_name&amp;quot;] )&lt;br /&gt;
	);&lt;br /&gt;
}&lt;br /&gt;
echo &amp;quot;&amp;lt;/ul&amp;gt;\n&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
$stmt-&amp;gt;close();&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Instead of binding the columns of the result set to variables, they are returned in an associative array.  '''$result-&amp;gt;fetch_assoc()''' returns a new array for each row in the result set, and when there are no more rows, it returns null, thereby exiting the loop.&lt;br /&gt;
&lt;br /&gt;
==== Troubleshooting ====&lt;br /&gt;
&lt;br /&gt;
If you are getting an error &amp;lt;code&amp;gt;call to undefined method mysqli_stmt::get_result()&amp;lt;/code&amp;gt;, you probably installed the '''php(5)-mysql''' instead of the '''php(5)-mysqlnd''' package.  To fix this, first uninstall the old package and then install the new one.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo yum remove php-mysql&lt;br /&gt;
$ sudo yum install php-mysqlnd&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Combined Queries ==&lt;br /&gt;
&lt;br /&gt;
You can also perform queries that both take input and produce output; you simply call both '''$stmt-&amp;gt;bind_param()''' and '''$stmt-&amp;gt;bind_result()'''.  For example, the following selects all employees in the department specified in the GET variable '''dept''':&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
require 'database.php';&lt;br /&gt;
&lt;br /&gt;
$dept = $_GET['dept'];&lt;br /&gt;
&lt;br /&gt;
$stmt = $mysqli-&amp;gt;prepare(&amp;quot;select first_name, last_name from employees where department=?&amp;quot;);&lt;br /&gt;
if(!$stmt){&lt;br /&gt;
	printf(&amp;quot;Query Prep Failed: %s\n&amp;quot;, $mysqli-&amp;gt;error);&lt;br /&gt;
	exit;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$stmt-&amp;gt;bind_param('s', $dept);&lt;br /&gt;
&lt;br /&gt;
$stmt-&amp;gt;execute();&lt;br /&gt;
&lt;br /&gt;
$stmt-&amp;gt;bind_result($first, $last);&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;&amp;lt;ul&amp;gt;\n&amp;quot;;&lt;br /&gt;
while($stmt-&amp;gt;fetch()){&lt;br /&gt;
	printf(&amp;quot;\t&amp;lt;li&amp;gt;%s %s&amp;lt;/li&amp;gt;\n&amp;quot;,&lt;br /&gt;
		htmlspecialchars($first),&lt;br /&gt;
		htmlspecialchars($last)&lt;br /&gt;
	);&lt;br /&gt;
}&lt;br /&gt;
echo &amp;quot;&amp;lt;/ul&amp;gt;\n&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
$stmt-&amp;gt;close();&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=SSH&amp;diff=2903</id>
		<title>SSH</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=SSH&amp;diff=2903"/>
		<updated>2023-09-01T20:33:48Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* SSH Configuration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Secure SHell, or '''SSH''', is the leading interface for connecting as an administrator from your local computer to something on the cloud.  You will be using exclusively SSH to execute commands and upload files to your cloud instance.  If you use a Git hosting service like BitBucket or Github, you will need SSH in order to save your changes there as well.&lt;br /&gt;
&lt;br /&gt;
SSH access requires that the ''sshd'' daemon is running on the remote machine.  By default, SSH is preinstalled on your EC2 instance.  If you are not using an EC2 instance, simply install '''ssh''' from yum or apt on the remote machine.&lt;br /&gt;
&lt;br /&gt;
== SSH Keys ==&lt;br /&gt;
&lt;br /&gt;
SSH can work using password-based authentication, but it is more common nowadays, and also more secure, to use ''public and private keys'', also known as a ''key pair''.&lt;br /&gt;
&lt;br /&gt;
Here's how it works.  You have a private copy of your key, called your '''private key'''.  Servers to which you want to connect have an analog to your private key called your '''public key'''.  When you attempt to connect to a server using your private key, the server checks to see if any of its public keys &amp;quot;fits&amp;quot; your private key, and if it finds a match, it lets you in.&lt;br /&gt;
&lt;br /&gt;
You can think of the ''private key'' as the &amp;quot;key&amp;quot; and the ''public key'' as the &amp;quot;lock&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
== SSH Configuration ==&lt;br /&gt;
&lt;br /&gt;
This section discusses how to set up your computer and your remote instance for SSH.  You need to do this only once.&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
=== Creating an SSH Key Pair ===&lt;br /&gt;
&lt;br /&gt;
You should create your own SSH Key Pair.  You will keep the private key on your own computer, and you will upload the public key to all places to which you need to connect.&lt;br /&gt;
&lt;br /&gt;
To generate a key pair, open a terminal ([[Workflow#Installing_a_Terminal_Emulator|on Windows, you'll need to have enabled WSL or installed Cygwin]] and run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;# Run on Local Machine in Terminal or Cygwin&lt;br /&gt;
$ ssh-keygen&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' Don't name the file unless you are using a CEC machine. If you are using a CEC machine, name the file ''/cygdrive/h/.ssh/id_rsa''&lt;br /&gt;
&lt;br /&gt;
For the purposes of this course, you do not need to enter a passphrase, although you would probably want one in real life.&lt;br /&gt;
&lt;br /&gt;
Your keys should have been created in ~/.ssh.  Check to make sure they exist using the ''ls'' command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ls ~/.ssh&lt;br /&gt;
id_rsa  id_rsa.pub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''id_rsa'' is your private key, and ''id_rsa.pub'' is the corresponding public key.  Let's look at the public signature of your key pair:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ cat ~/.ssh/id_rsa.pub&lt;br /&gt;
ssh-rsa AAAA3Bblahblahblahblah yourname@somedomain&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We will need this later.  Let's now add our key to the ''ssh-agent''.&lt;br /&gt;
&lt;br /&gt;
==== SSH Agent: OS X ====&lt;br /&gt;
&lt;br /&gt;
Run the following command to add your key to the SSH agent in Mac OS X.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;# Non-Cygwin&lt;br /&gt;
$ ssh-add&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== SSH Agent: WSL or Cygwin ====&lt;br /&gt;
&lt;br /&gt;
In order to make the SSH agent run when you start your terminal, you need to run a couple more commands (these will add a line to your .bashrc file, which runs automatically on startup):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Cygwin only&lt;br /&gt;
$ echo &amp;quot;eval \`ssh-agent -s\`; ssh-add&amp;quot; &amp;gt;&amp;gt; ~/.bashrc&lt;br /&gt;
$ source ~/.bashrc # reload the Bash shell&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get this scary-looking error after you run the second command…&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;br /&gt;
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @&lt;br /&gt;
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…then you need to do the following to fix the permissions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ chgrp Users &amp;lt;/path/to/id_rsa&amp;gt;&lt;br /&gt;
$ chmod 600 &amp;lt;/path/to/id_rsa&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Amazon EC2 SSH Configuration ===&lt;br /&gt;
&lt;br /&gt;
When you first created your EC2 instance, you downloaded a *.pem file.  This is the ''private key'' for the default user ('''ec2-user''' on AMI).  We need use this key to connect to your instance using the default user, at which point we will create a new custom user.  We will give that new user the public key that you created in the previous step.  You will then be able to log into your custom user using your personal key pair, so you won't need the default user again (although you should keep the *.pem file around just in case).&lt;br /&gt;
&lt;br /&gt;
==== Logging In as the Default User ====&lt;br /&gt;
&lt;br /&gt;
To connect to the default user on your Amazon EC2 instance, run this command in your terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run on Local Machine&lt;br /&gt;
$ ssh -i &amp;lt;/path/to/default-privatekey.pem&amp;gt; ec2-user@&amp;lt;ec2-xx-xx-xx-xx.compute-1.amazonaws.com&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important:''' As soon as you are able to successfully log in, commands you type into your prompt will be executed on the remote instance, ''not'' your local machine.&lt;br /&gt;
&lt;br /&gt;
If you get this scary-looking warning:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;br /&gt;
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @&lt;br /&gt;
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
…then you need to correctly set the permissions on your *.pem file.  You should know how to do this from the Linux guide, but in case you didn't catch that detail, run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run on Local Machine&lt;br /&gt;
&lt;br /&gt;
# Cygwin Only:&lt;br /&gt;
&lt;br /&gt;
 $ chgrp Users &amp;lt;/path/to/default-privatekey.pem&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# For Everyone:&lt;br /&gt;
$ chmod 600 &amp;lt;/path/to/default-privatekey.pem&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Food for Thought:''' Why you wouldn't want other people viewing your private key file?&lt;br /&gt;
&lt;br /&gt;
==== Creating a New User with SSH Permissions ====&lt;br /&gt;
&lt;br /&gt;
First, you need to create your new user with sudo and SSH permissions.  Again, the instructions for this are in the Linux guide, but to keep everything in one place, the commands are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Run these on your instance, not on your local machine!&lt;br /&gt;
&lt;br /&gt;
# Don't forget to customize `&amp;lt;My Full Name&amp;gt;` and `&amp;lt;usernameHere&amp;gt;`:&lt;br /&gt;
$ sudo useradd -r -m -c &amp;quot;&amp;lt;My Full Name&amp;gt;&amp;quot; &amp;lt;usernameHere&amp;gt;&lt;br /&gt;
$ sudo passwd &amp;lt;usernameHere&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# You need to add your username to the sudoers list.  Refer to the Linux guide for details.&lt;br /&gt;
# Look around line 101.&lt;br /&gt;
$ sudo visudo &lt;br /&gt;
&lt;br /&gt;
# Restart the SSH server:&lt;br /&gt;
$ sudo service ssh restart || sudo service sshd restart&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Okay, cool: we have created our custom username on our remote instance.  Now, we need to enable this account to accept our SSH key when authenticating.  To do this, we need to add our public key to a file named '''authorized_keys''', which is stored in your remote username's SSH configuration directory.&lt;br /&gt;
&lt;br /&gt;
To create the directory and edit the file, run on your instance:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Switch to our own user to ensure that permissions are set correctly:&lt;br /&gt;
$ su &amp;lt;username here&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# Change the working directory to our user's home directory:&lt;br /&gt;
$ cd&lt;br /&gt;
&lt;br /&gt;
# Make the nonexistent SSH configuration directory and set its permissions:&lt;br /&gt;
$ mkdir .ssh&lt;br /&gt;
$ chmod 700 .ssh&lt;br /&gt;
&lt;br /&gt;
# Create the `authorized_keys` file and set the permissions&lt;br /&gt;
$ touch .ssh/authorized_keys&lt;br /&gt;
$ chmod 600 .ssh/authorized_keys&lt;br /&gt;
&lt;br /&gt;
# Edit the `authorized_keys` file&lt;br /&gt;
$ nano .ssh/authorized_keys&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more detail on editing files on the command line, see [[Linux#File Editors|the Linux guide]].&lt;br /&gt;
&lt;br /&gt;
Inside of the `authorized_keys` file, paste in your public key.  Your public key is the content of `~/.ssh/id_rsa.pub` '''on your local machine''' (it starts with &amp;quot;ssh-rsa&amp;quot;).  There are a few ways to get it onto your clipboard:&lt;br /&gt;
&lt;br /&gt;
# '''OS X Only:''' Open a new Terminal and run: &amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;cat ~/.ssh/id_rsa.pub | pbcopy&amp;lt;/source&amp;gt; This immediately copies the contents of your public key to your clipboard.&lt;br /&gt;
# '''Windows Only:''' Navigate to id_rsa.pub manually, open it in your favorite text editor (like Notepad++), select all, and copy.  The location of id_rsa.pub might be: ''C:\cygwin\home\username\.ssh\id_rsa.pub''&lt;br /&gt;
# '''&amp;amp;#42;NIX Only:''' Open a new Terminal and copy the output of the following command: &amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;cat ~/.ssh/id_rsa.pub&amp;lt;/source&amp;gt; Note that this won't work as advertised in Cygwin because Cygwin adds extra line breaks when you try to copy out of it.&lt;br /&gt;
&lt;br /&gt;
When finished, save and close `authorized_keys`.&lt;br /&gt;
&lt;br /&gt;
'''Food for Thought:''' How would you enable your remote user to authenticate over SSH using the same default key instead of the one you created using ''ssh-keygen''?&lt;br /&gt;
&lt;br /&gt;
==== Logging In as your New User ====&lt;br /&gt;
&lt;br /&gt;
Let's test whether we can log into our instance using our own username and our own key pair. Open up a new Terminal or Cygwin window '''on your local machine''' (not from ec2) and run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ssh &amp;lt;username here&amp;gt;@&amp;lt;ec2-xx-xx-xx-xx.amazonaws.com&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is how you will be SSHing into your instances for the remainder of the semester.&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Troubleshooting ===&lt;br /&gt;
&lt;br /&gt;
Almost everyone receives the following error at some point in their career: &amp;lt;code&amp;gt;Permission denied (publickey)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Here are some possible causes for the error.&lt;br /&gt;
&lt;br /&gt;
==== The Authorized Keys File ====&lt;br /&gt;
&lt;br /&gt;
Make sure that your remote ''authorized_keys'' file contains ''exactly'' your public signature from ''id_rsa.pub''.&lt;br /&gt;
&lt;br /&gt;
===== Pasting into Vi =====&lt;br /&gt;
&lt;br /&gt;
If you used vi to edit your file and you forgot to enter &amp;quot;insert&amp;quot; mode before pasting in your key, it is possible that you lost the first &amp;quot;s&amp;quot; in &amp;quot;ssh-rsa&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Check the contents of authorized_keys via &amp;lt;code&amp;gt;cat ~/.ssh/authorized_keys&amp;lt;/code&amp;gt; on your server.  If the output starts with &amp;quot;sh-rsa&amp;quot; instead of &amp;quot;ssh-rsa&amp;quot;, edit the authorized_keys file and add the second '''s'''.&lt;br /&gt;
&lt;br /&gt;
===== Unintentional Line Breaks =====&lt;br /&gt;
&lt;br /&gt;
If you got your key via a &amp;lt;code&amp;gt;cat ~/.ssh/id_rsa.pub&amp;lt;/code&amp;gt; and then copied it from the terminal, it's possible that you unintentionally introduced line breaks.  Ensure that the key is represented by only one line of text.&lt;br /&gt;
&lt;br /&gt;
==== Permissions ====&lt;br /&gt;
&lt;br /&gt;
They need to be correct on both the client side and on the server side.&lt;br /&gt;
&lt;br /&gt;
* Local ''.ssh'' = 700&lt;br /&gt;
* Local ''id_rsa'' = 600&lt;br /&gt;
* Remote ''.ssh'' = 700&lt;br /&gt;
* Remote ''authorized_keys'' = 600&lt;br /&gt;
&lt;br /&gt;
If you are in Cygwin and the permissions don't seem to change, you might need to add the troubled file to a usergroup, like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ chgrp Users .ssh/id_rsa&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== The SSH Agent ====&lt;br /&gt;
&lt;br /&gt;
You need to be sending the correct key along with your SSH Agent.  Run the following command, and you should see some output:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ssh-add -l&lt;br /&gt;
2048 ab:cd:ef:ab:cd:ef:ab:cd:ef:ab:cd:ef:ab:cd:ef:ab:cd /path/to/.ssh/id_rsa (RSA)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don't see any output, or if the output does not contain your ''id_rsa'', then you need to run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ssh-add &amp;lt;/path/to/.ssh/id_rsa&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== More SSH Server Configurations ===&lt;br /&gt;
&lt;br /&gt;
Up to this point, we have been using all of the default SSH configurations.  Like most things in Linux, SSH can be customized.&lt;br /&gt;
&lt;br /&gt;
For the purposes of CSE 330, the additional configurations in this short section are optional; this serves only as a reference.&lt;br /&gt;
&lt;br /&gt;
==== Disabling Root Access ====&lt;br /&gt;
&lt;br /&gt;
It is almost always a good idea to disable root access over ssh. This could be done by editing ''/etc/ssh/sshd_config'' and setting  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;PermitRootLogin no&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will need to restart the SSH server for changes to take effect:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo service sshd restart&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enabling Password-Based Authentication ====&lt;br /&gt;
&lt;br /&gt;
Up to this point, we have been using key pairs for SSH.  A public/private key pair is generally considered to be more secure, but it requires that you always have access to your private key file when you want to log into your remote machine.&lt;br /&gt;
&lt;br /&gt;
By default, EC2 instances allow only public/private key pair authentication.  You can enable password-based authentication by setting the PaswordAuthentication option in ''/etc/ssh/sshd_config'' to '''yes''':&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;PasswordAuthentication yes&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There may be a line with this option that you can un-comment.  For me, it is line 25.  You will need to restart the server for changes to take effect.&lt;br /&gt;
&lt;br /&gt;
If possible, however, you should restrict yourself to using private and public keys.&lt;br /&gt;
&lt;br /&gt;
== Using SSH ==&lt;br /&gt;
&lt;br /&gt;
Once you have completed the [[#SSH Configuration]] section above, all you need to do in order to SSH into your instance is to open a terminal and run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ ssh &amp;lt;username here&amp;gt;@&amp;lt;ec2-xx-xx-xx-xx.compute-1.amazonaws.com&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PuTTY ===&lt;br /&gt;
&lt;br /&gt;
'''This short section about PuTTY serves only as a reference.'''&lt;br /&gt;
&lt;br /&gt;
If you have Cygwin available, you should use it to SSH into your instance.  However, if you are using a different computer, you might not have Cygwin at your fingertips.  In this case, a lighter-weight SSH client called '''PuTTY''' is available for Windows.&lt;br /&gt;
&lt;br /&gt;
You can download PuTTY from: http://www.chiark.greenend.org.uk/~sgtatham/putty/&lt;br /&gt;
&lt;br /&gt;
Amazon provides [http://docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide/ConnectToInstanceLinux.html#connect-from-windows-machine a great tutorial on how to connect to a virtual machine from Windows].&lt;br /&gt;
&lt;br /&gt;
PuTTY is fairly simple and straight forward with one caveat: Amazon's ''*.pem'' files are SSH private key files, and they need to be converted to PuTTY's own '''.ppk''' format.  To do this, use the ''puttygen.exe'' utility available from the same page as PuTTY.  Select &amp;quot;Import&amp;quot; under the conversions menu, load the amazon ''*.pem'' key file, and press the &amp;quot;Save Private Key&amp;quot; button.&lt;br /&gt;
&lt;br /&gt;
Copy and paste works similarly to the X Window System in Unix. You use the left mouse button to select text in the PuTTY window. The act of selection automatically copies the text to the clipboard: there is no need to press Ctrl-Ins or Ctrl-C or anything else. In fact, pressing Ctrl-C will send a Ctrl-C character to the other end of your connection (just like it does the rest of the time), which may have unpleasant effects. The only thing you need to do, to copy text to the clipboard, is to select it.&lt;br /&gt;
&lt;br /&gt;
To paste the clipboard contents into a PuTTY window, by default you click the right mouse button. If you have a three-button mouse and are used to X applications, you can configure pasting to be done by the middle button instead, but this is not the default because most Windows users don't have a middle button at all. &lt;br /&gt;
&lt;br /&gt;
Here is a good PuTTY tutorial that you might find useful to get started: http://kb.mediatemple.net/questions/1595/Using+SSH+in+Putty+%28Windows%29&lt;br /&gt;
&lt;br /&gt;
== SSHFS and SFTP ==&lt;br /&gt;
&lt;br /&gt;
In addition to just SSH, your SSH server also supports '''SSHFS''', which enables you to mount your remote instance as a disk on your local computer, and '''SFTP''', which is a file transfer protocol that enables you to upload files directly to your instance.&lt;br /&gt;
&lt;br /&gt;
=== SSHFS ===&lt;br /&gt;
&lt;br /&gt;
SSHFS is a filesystem client which allows secure mounting of remote file systems. While there are other ways to mount remote file systems, SSHFS has the advantage of being able to mount a file system located on any host that has an SSH daemon running without any host side installation or configuration. This means that you can easily access and edit your files using all of your local applications including IDEs. &lt;br /&gt;
&lt;br /&gt;
As you may have inferred from the name, the underlying implementation utilizes SSH File Transfer Protocol in combination with FUSE, a package now included in the kernel that allows unprivileged users to easily create their own file systems in userspace (see the wikipedia entry for more information [http://en.wikipedia.org/wiki/Filesystem_in_Userspace]).&lt;br /&gt;
&lt;br /&gt;
To mount a share using password based authentication, the command is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sshfs &amp;lt;user&amp;gt;@&amp;lt;domain&amp;gt;:&amp;lt;/path/to/remote/directory&amp;gt; &amp;lt;/path/to/local/mountpoint&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, to mount the directory /home/joe/myfiles in the user ''joe'''s home directory for a machine with the domain schmoesfiles.org using SSHFS you would enter the command&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sshfs joe@www.schmoesfiles.org:myfiles&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that if you are using public key authentication, the command to mount the remote filesystem may need to be slightly different:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sshfs -o IdentityFile=&amp;lt;/path/to/private/key&amp;gt; &amp;lt;user&amp;gt;@&amp;lt;domain&amp;gt;:&amp;lt;/path/to/remote/directory&amp;gt; &amp;lt;/path/to/local/mountpoint&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To unmount the filesystem, you can use the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ fusermount -u &amp;lt;/path/to/local/mountpoint&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SFTP ===&lt;br /&gt;
&lt;br /&gt;
Any server running an SSH server is also compatible with '''SFTP''' or Secure File Transfer Protocol.  (Compare to FTP, or File Transfer Protocol.)  SFTP is a convenient way to edit files on your computer and then upload them to your server in just a few clicks.&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 2]]&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=HTML_Forms&amp;diff=2901</id>
		<title>HTML Forms</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=HTML_Forms&amp;diff=2901"/>
		<updated>2023-08-28T17:15:14Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* HTTP Headers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The contents of a web page often changes depending on how you requested that page.  For example, when you perform a web search, the contents of the search list changes depending on your query.  This is done by way of HTTP request variables (about which you will learn more in Module 2).&lt;br /&gt;
&lt;br /&gt;
The most fundamental way to make a web page sent HTTP request variables to another page is by using HTML Forms.  This article describes this process and how to implement it in your code.&lt;br /&gt;
&lt;br /&gt;
== HTTP Request Variables ==&lt;br /&gt;
&lt;br /&gt;
Visit your favorite search engine, and search for &amp;quot;QUERY&amp;quot;.  Now, look at your address bar.  Can you find your query &amp;quot;QUERY&amp;quot; somewhere in the URL?&lt;br /&gt;
&lt;br /&gt;
Your search engine probably used an HTTP Request Variable to send your desired query to the search page.  Here is how it might have worked:&lt;br /&gt;
&lt;br /&gt;
[[File:HTMLForm.png]]&lt;br /&gt;
&lt;br /&gt;
You can see that we didn't just go to example.com/search; we also incorporated the search query into the '''query string''' of the URL, where query stream &lt;br /&gt;
&lt;br /&gt;
=== Code Example ===&lt;br /&gt;
&lt;br /&gt;
The syntax for making a form in HTML is relatively straightforward.  The HTML for the above example could be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;http://example.com/search&amp;quot; method=&amp;quot;GET&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;label&amp;gt;Search Query: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;q&amp;quot; /&amp;gt;&amp;lt;/label&amp;gt;&lt;br /&gt;
	&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Search&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The '''&amp;lt;label&amp;gt;''' tag above allows text to &amp;quot;label&amp;quot; an input field.  When anything in the label is clicked, the input field will become focussed.&lt;br /&gt;
&lt;br /&gt;
== HTTP Request Methods ==&lt;br /&gt;
&lt;br /&gt;
In the above example, we used the GET method for transferring variables from our form to our destination page.  There are two widely supported options for transferring the variables:&lt;br /&gt;
&lt;br /&gt;
# '''GET''' transfers the variables in the URL.&lt;br /&gt;
# '''POST''' transfers the variables as an HTTP header.&lt;br /&gt;
&lt;br /&gt;
What does &amp;quot;as an HTTP header&amp;quot; mean?&lt;br /&gt;
&lt;br /&gt;
=== HTTP Headers ===&lt;br /&gt;
&lt;br /&gt;
Whenever you request a page on the http:// protocol, your browser sends a ''request header''.  Your server responds with a ''response header'' followed by the content of your page.  You never see the request or response headers unless you have tools that let you see them.&lt;br /&gt;
&lt;br /&gt;
To let you have an idea, here are the request and response headers when I visit http://www.w3.org/ in Firefox:&lt;br /&gt;
&lt;br /&gt;
'''Request Headers:'''&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
GET / HTTP/1.1&lt;br /&gt;
Host: www.w3.org&lt;br /&gt;
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:19.0) Gecko/20100101 Firefox/19.0&lt;br /&gt;
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&lt;br /&gt;
Accept-Language: en-US,en;q=0.5&lt;br /&gt;
Accept-Encoding: gzip, deflate&lt;br /&gt;
Connection: keep-alive&lt;br /&gt;
If-Modified-Since: Sat, 16 Mar 2013 09:16:37 GMT&lt;br /&gt;
If-None-Match: &amp;quot;8c8c-4d80736774740;89-3f26bd17a2f00&amp;quot;&lt;br /&gt;
Cache-Control: max-age=0&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Response Headers:'''&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
HTTP/1.1 200 OK&lt;br /&gt;
Date: Sat, 16 Mar 2013 19:42:55 GMT&lt;br /&gt;
Server: Apache/2&lt;br /&gt;
Content-Location: Home.html&lt;br /&gt;
Vary: negotiate,accept&lt;br /&gt;
TCN: choice&lt;br /&gt;
Last-Modified: Sat, 16 Mar 2013 09:16:37 GMT&lt;br /&gt;
Etag: &amp;quot;8cc6-4d80736774740;89-3f26bd17a2f00&amp;quot;&lt;br /&gt;
Accept-Ranges: bytes&lt;br /&gt;
Content-Length: 36038&lt;br /&gt;
Cache-Control: max-age=600&lt;br /&gt;
Expires: Sat, 16 Mar 2013 19:52:55 GMT&lt;br /&gt;
P3P: policyref=&amp;quot;http://www.w3.org/2001/05/P3P/p3p.xml&amp;quot;&lt;br /&gt;
Connection: close&lt;br /&gt;
Content-Type: text/html; charset=utf-8&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can see that in the request header, information is sent about what browser and operating system I'm using (my ''user agent''), what language I prefer (in my case, ''en-US''), and the like.  If you have cookies for a site, they get transfered via a request header.  In the response header, we can see that the request was successful (HTTP code 200), that I am receiving an HTML document with the UTF-8 charset (in ''Content-Type''), and other various information.  All of these headers are standard; you can implement less-common headers as well.&lt;br /&gt;
&lt;br /&gt;
=== When to use GET vs. POST ===&lt;br /&gt;
&lt;br /&gt;
Here are some rules of thumb to help you decide whether to use GET or POST for a certain form.&lt;br /&gt;
&lt;br /&gt;
* If you would like the user of your application to be able to ''bookmark the destination page'' for later use (e.g. search results), you need to use '''GET''', because the bookmark will contain the entire URL, including the request variables.&lt;br /&gt;
* If you are transmitting ''sensitive information'' like passwords, you should use '''POST''', because POST variables will not appear in a user's browsing history, but GET variables will.&lt;br /&gt;
* If the data you are transmitting is large (over about 200 bytes), you need to use '''POST''', since some browsers will truncate the URL string after 256 characters.&lt;br /&gt;
* If the destination page takes the information from the form and modifies something in a database, it is best practice to use '''POST'''.&lt;br /&gt;
&lt;br /&gt;
=== Technicalities ===&lt;br /&gt;
&lt;br /&gt;
Although it is safe to think about POST variables as being transmitted as a header, this is technically not the case.  In reality, POST variables are sent in the request body.  The server knows to read the POST variables from the request body because of a '''application/x-www-form-urlencoded''' request content type header.&lt;br /&gt;
&lt;br /&gt;
Additionally, there has been a recent resurgence in so-called [[wikipedia:CRUD|CRUD]]; that is, additional HTTP request types beyond GET and POST: PUT, DELETE, OPTIONS, etc.  CRUD request types are beyond the scope of this course, but it is worth the time reading up on their meaning if you find yourself working with a RESTful web framework like Ruby on Rails.&lt;br /&gt;
&lt;br /&gt;
== Input Types ==&lt;br /&gt;
&lt;br /&gt;
In the example above, we used just two input types: a '''text''' field and a '''submit''' button.  In reality, there are over 20 different types.  Some of the more common types include:&lt;br /&gt;
&lt;br /&gt;
* '''hidden:''' allows for a variable to be passed as part of a form without requiring that the user input any data.&lt;br /&gt;
* '''password:''' allows for text to be hidden while typed.&lt;br /&gt;
* '''number:''' like a text box, but forces the content to be numerical.&lt;br /&gt;
** ''Note:'' You can set the '''step''', '''min''', and '''max''' attributes on your '''number''' input to change the precision of the number accepted.  For example, the following input field would accept only integers between 0 and 100 inclusive:&lt;br /&gt;
**: &amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&amp;lt;input type=&amp;quot;number&amp;quot; name=&amp;quot;percentage&amp;quot; step=&amp;quot;1&amp;quot; min=&amp;quot;0&amp;quot; max=&amp;quot;100&amp;quot; /&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
* '''checkbox:''' a yes-or-no checkbox.&lt;br /&gt;
* '''radio:''' a multiple-choice question.  Use multiple input fields, all with the same ''name'' but different ''value''.&lt;br /&gt;
* '''file:''' allows for file uploads.  (We will deal with this more in module 2.)&lt;br /&gt;
&lt;br /&gt;
For a complete list, see [https://www.w3.org/TR/html5/forms.html#the-input-element section 4.10.7 of the HTML5 spec].&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 1]]&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_Git&amp;diff=2900</id>
		<title>M1 Introduction to Git</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_Git&amp;diff=2900"/>
		<updated>2023-08-15T20:41:45Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Git */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''NOTE: This is an extremely simplified guide to Git meant to kickstart your work in this course. We ''strongly'' recommend you read the [[M1 Git Extended|Git Extended]] reading.'''&lt;br /&gt;
&lt;br /&gt;
== Git ==&lt;br /&gt;
&lt;br /&gt;
=== Installation ===&lt;br /&gt;
Git may already be installed on your device. You can check this by running&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;git version&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it's not installed...&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''On your AWS Instance'''&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# install git using the &amp;quot;yum&amp;quot; linux package manager&lt;br /&gt;
$ sudo yum install git&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''After installation, make sure you complete this final step'''&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# Set the name and email for your git usage. &lt;br /&gt;
# This does not have to match your GitHub account&lt;br /&gt;
&lt;br /&gt;
# You can think of this as signing your name on your changes&lt;br /&gt;
&lt;br /&gt;
$ git config --global user.name &amp;quot;&amp;lt;Your Name&amp;gt;&amp;quot;&lt;br /&gt;
$ git config --global user.email &amp;quot;&amp;lt;you@example.com&amp;gt;&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Why Git? ===&lt;br /&gt;
&lt;br /&gt;
Git is a very powerful tool that's critical to modern software development. It's significance is rooted in three core features:&lt;br /&gt;
&lt;br /&gt;
==== Distributed Version Control ====&lt;br /&gt;
Think of Git as a cookbook shared among several chefs. Each chef has a complete copy of the recipes, so they can all experiment and make changes without waiting for one another. If one chef spills sauce on their copy, the others are unaffected. Likewise, each chef can peek into each other's copies to see new recipes or changes.&lt;br /&gt;
&lt;br /&gt;
In traditional centralized version control, there is a single &amp;quot;master&amp;quot; copy of the code. In contrast, Git's distributed nature means that every developer has a full-fledged copy of not only the entire codebase but also all the branches within it, including their respective histories. This structure allows more parallel development, supports experimentation with different parts of the code in isolation, and reduces reliance on a central server, thereby minimizing potential points of failure.&lt;br /&gt;
&lt;br /&gt;
==== History and Tracking ====&lt;br /&gt;
Imagine your code as a time-traveling book where you can flip back to see what was written at any point in time. You can even find out who wrote each sentence and why.&lt;br /&gt;
&lt;br /&gt;
Git keeps a detailed log of every change made to the code, including who made it and why (via commit messages). This allows for greater accountability and ease of tracking changes over time. If a bug is discovered, developers can quickly identify when it was introduced and by whom, facilitating a quicker resolution.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Branching and Merging ====&lt;br /&gt;
You can think of git branches as individual workspaces within a repository. Each branch allows for independent development, experimentation, or bug-fixing, and acts like a parallel universe to the main codebase. Changes made within a branch do not affect other branches, giving developers the freedom to explore and innovate without risk to the stable versions of the project. When a feature is completed or a bug is fixed, the branch can be merged back into the main codebase, seamlessly integrating the updates.&lt;br /&gt;
&lt;br /&gt;
===== Conflict Resolution =====&lt;br /&gt;
''' Without Merge Conflicts '''&lt;br /&gt;
&lt;br /&gt;
Imagine two developers working on two new features, each in their own branch. If both developers are working on different parts of the codebase, or different files altogether, their changes can typically be merged back into the main codebase without any conflicts. The modifications are independent of each other and do not overlap, allowing for a seamless merge.&lt;br /&gt;
&lt;br /&gt;
'''With Merge Conflicts'''&lt;br /&gt;
&lt;br /&gt;
Now consider a scenario where both developers are working on the same part of the code or the same file within their respective branches. When they try to merge their changes back into the main codebase, there may be conflicts where their changes overlap. Git will not know which changes to keep and which to discard, leading to a merge conflict.&lt;br /&gt;
&lt;br /&gt;
In this situation, manual intervention is needed to resolve the conflicts. The developers must review the conflicting changes, decide which to keep or how to combine them, and then commit the resolved code. Command line tools and graphic interfaces (likely built into your IDE) can assist in this process, but understanding the context of the changes and clear communication between developers is crucial for a successful resolution.&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_Git&amp;diff=2899</id>
		<title>M1 Introduction to Git</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_Git&amp;diff=2899"/>
		<updated>2023-08-15T20:24:30Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Conflict Resolution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''NOTE: This is an extremely simplified guide to Git meant to kickstart your work in this course. We ''strongly'' recommend you read the [[M1 Git Extended|Git Extended]] reading.'''&lt;br /&gt;
&lt;br /&gt;
== Git ==&lt;br /&gt;
&lt;br /&gt;
'''Git''' is a ''distributed version control system.'' It enables you to:&lt;br /&gt;
# Keep track of revisions to your files&lt;br /&gt;
# Push and pull your revisions to other computers or servers&lt;br /&gt;
# Collaborate with other people on the same project&lt;br /&gt;
&lt;br /&gt;
=== Why Git? ===&lt;br /&gt;
&lt;br /&gt;
Git is a very powerful tool that's critical to modern software development. It's significance is rooted in three core features:&lt;br /&gt;
&lt;br /&gt;
==== Distributed Version Control ====&lt;br /&gt;
Think of Git as a cookbook shared among several chefs. Each chef has a complete copy of the recipes, so they can all experiment and make changes without waiting for one another. If one chef spills sauce on their copy, the others are unaffected. Likewise, each chef can peek into each other's copies to see new recipes or changes.&lt;br /&gt;
&lt;br /&gt;
In traditional centralized version control, there is a single &amp;quot;master&amp;quot; copy of the code. In contrast, Git's distributed nature means that every developer has a full-fledged copy of not only the entire codebase but also all the branches within it, including their respective histories. This structure allows more parallel development, supports experimentation with different parts of the code in isolation, and reduces reliance on a central server, thereby minimizing potential points of failure.&lt;br /&gt;
&lt;br /&gt;
==== History and Tracking ====&lt;br /&gt;
Imagine your code as a time-traveling book where you can flip back to see what was written at any point in time. You can even find out who wrote each sentence and why.&lt;br /&gt;
&lt;br /&gt;
Git keeps a detailed log of every change made to the code, including who made it and why (via commit messages). This allows for greater accountability and ease of tracking changes over time. If a bug is discovered, developers can quickly identify when it was introduced and by whom, facilitating a quicker resolution.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Branching and Merging ====&lt;br /&gt;
You can think of git branches as individual workspaces within a repository. Each branch allows for independent development, experimentation, or bug-fixing, and acts like a parallel universe to the main codebase. Changes made within a branch do not affect other branches, giving developers the freedom to explore and innovate without risk to the stable versions of the project. When a feature is completed or a bug is fixed, the branch can be merged back into the main codebase, seamlessly integrating the updates.&lt;br /&gt;
&lt;br /&gt;
===== Conflict Resolution =====&lt;br /&gt;
''' Without Merge Conflicts '''&lt;br /&gt;
&lt;br /&gt;
Imagine two developers working on two new features, each in their own branch. If both developers are working on different parts of the codebase, or different files altogether, their changes can typically be merged back into the main codebase without any conflicts. The modifications are independent of each other and do not overlap, allowing for a seamless merge.&lt;br /&gt;
&lt;br /&gt;
'''With Merge Conflicts'''&lt;br /&gt;
&lt;br /&gt;
Now consider a scenario where both developers are working on the same part of the code or the same file within their respective branches. When they try to merge their changes back into the main codebase, there may be conflicts where their changes overlap. Git will not know which changes to keep and which to discard, leading to a merge conflict.&lt;br /&gt;
&lt;br /&gt;
In this situation, manual intervention is needed to resolve the conflicts. The developers must review the conflicting changes, decide which to keep or how to combine them, and then commit the resolved code. Command line tools and graphic interfaces (likely built into your IDE) can assist in this process, but understanding the context of the changes and clear communication between developers is crucial for a successful resolution.&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_Git&amp;diff=2898</id>
		<title>M1 Introduction to Git</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_Git&amp;diff=2898"/>
		<updated>2023-08-15T20:23:50Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* = Distributed Version Control */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''NOTE: This is an extremely simplified guide to Git meant to kickstart your work in this course. We ''strongly'' recommend you read the [[M1 Git Extended|Git Extended]] reading.'''&lt;br /&gt;
&lt;br /&gt;
== Git ==&lt;br /&gt;
&lt;br /&gt;
'''Git''' is a ''distributed version control system.'' It enables you to:&lt;br /&gt;
# Keep track of revisions to your files&lt;br /&gt;
# Push and pull your revisions to other computers or servers&lt;br /&gt;
# Collaborate with other people on the same project&lt;br /&gt;
&lt;br /&gt;
=== Why Git? ===&lt;br /&gt;
&lt;br /&gt;
Git is a very powerful tool that's critical to modern software development. It's significance is rooted in three core features:&lt;br /&gt;
&lt;br /&gt;
==== Distributed Version Control ====&lt;br /&gt;
Think of Git as a cookbook shared among several chefs. Each chef has a complete copy of the recipes, so they can all experiment and make changes without waiting for one another. If one chef spills sauce on their copy, the others are unaffected. Likewise, each chef can peek into each other's copies to see new recipes or changes.&lt;br /&gt;
&lt;br /&gt;
In traditional centralized version control, there is a single &amp;quot;master&amp;quot; copy of the code. In contrast, Git's distributed nature means that every developer has a full-fledged copy of not only the entire codebase but also all the branches within it, including their respective histories. This structure allows more parallel development, supports experimentation with different parts of the code in isolation, and reduces reliance on a central server, thereby minimizing potential points of failure.&lt;br /&gt;
&lt;br /&gt;
==== History and Tracking ====&lt;br /&gt;
Imagine your code as a time-traveling book where you can flip back to see what was written at any point in time. You can even find out who wrote each sentence and why.&lt;br /&gt;
&lt;br /&gt;
Git keeps a detailed log of every change made to the code, including who made it and why (via commit messages). This allows for greater accountability and ease of tracking changes over time. If a bug is discovered, developers can quickly identify when it was introduced and by whom, facilitating a quicker resolution.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Branching and Merging ====&lt;br /&gt;
You can think of git branches as individual workspaces within a repository. Each branch allows for independent development, experimentation, or bug-fixing, and acts like a parallel universe to the main codebase. Changes made within a branch do not affect other branches, giving developers the freedom to explore and innovate without risk to the stable versions of the project. When a feature is completed or a bug is fixed, the branch can be merged back into the main codebase, seamlessly integrating the updates.&lt;br /&gt;
&lt;br /&gt;
===== Conflict Resolution =====&lt;br /&gt;
''' Without Merge Conflicts '''&lt;br /&gt;
Imagine two developers working on two new features, each in their own branch. If both developers are working on different parts of the codebase, or different files altogether, their changes can typically be merged back into the main codebase without any conflicts. The modifications are independent of each other and do not overlap, allowing for a seamless merge.&lt;br /&gt;
&lt;br /&gt;
'''With Merge Conflicts'''&lt;br /&gt;
Now consider a scenario where both developers are working on the same part of the code or the same file within their respective branches. When they try to merge their changes back into the main codebase, there may be conflicts where their changes overlap. Git will not know which changes to keep and which to discard, leading to a merge conflict.&lt;br /&gt;
&lt;br /&gt;
In this situation, manual intervention is needed to resolve the conflicts. The developers must review the conflicting changes, decide which to keep or how to combine them, and then commit the resolved code. Command line tools and graphic interfaces (likely built into your IDE) can assist in this process, but understanding the context of the changes and clear communication between developers is crucial for a successful resolution.&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_Git&amp;diff=2897</id>
		<title>M1 Introduction to Git</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_Git&amp;diff=2897"/>
		<updated>2023-08-15T20:22:54Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Git */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''NOTE: This is an extremely simplified guide to Git meant to kickstart your work in this course. We ''strongly'' recommend you read the [[M1 Git Extended|Git Extended]] reading.'''&lt;br /&gt;
&lt;br /&gt;
== Git ==&lt;br /&gt;
&lt;br /&gt;
'''Git''' is a ''distributed version control system.'' It enables you to:&lt;br /&gt;
# Keep track of revisions to your files&lt;br /&gt;
# Push and pull your revisions to other computers or servers&lt;br /&gt;
# Collaborate with other people on the same project&lt;br /&gt;
&lt;br /&gt;
=== Why Git? ===&lt;br /&gt;
&lt;br /&gt;
Git is a very powerful tool that's critical to modern software development. It's significance is rooted in three core features:&lt;br /&gt;
&lt;br /&gt;
==== Distributed Version Control ===&lt;br /&gt;
Think of Git as a cookbook shared among several chefs. Each chef has a complete copy of the recipes, so they can all experiment and make changes without waiting for one another. If one chef spills sauce on their copy, the others are unaffected. Likewise, each chef can peek into each other's copies to see new recipes or changes.&lt;br /&gt;
&lt;br /&gt;
In traditional centralized version control, there is a single &amp;quot;master&amp;quot; copy of the code. In contrast, Git's distributed nature means that every developer has a full-fledged copy of not only the entire codebase but also all the branches within it, including their respective histories. This structure allows more parallel development, supports experimentation with different parts of the code in isolation, and reduces reliance on a central server, thereby minimizing potential points of failure.&lt;br /&gt;
&lt;br /&gt;
==== History and Tracking ====&lt;br /&gt;
Imagine your code as a time-traveling book where you can flip back to see what was written at any point in time. You can even find out who wrote each sentence and why.&lt;br /&gt;
&lt;br /&gt;
Git keeps a detailed log of every change made to the code, including who made it and why (via commit messages). This allows for greater accountability and ease of tracking changes over time. If a bug is discovered, developers can quickly identify when it was introduced and by whom, facilitating a quicker resolution.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Branching and Merging ====&lt;br /&gt;
You can think of git branches as individual workspaces within a repository. Each branch allows for independent development, experimentation, or bug-fixing, and acts like a parallel universe to the main codebase. Changes made within a branch do not affect other branches, giving developers the freedom to explore and innovate without risk to the stable versions of the project. When a feature is completed or a bug is fixed, the branch can be merged back into the main codebase, seamlessly integrating the updates.&lt;br /&gt;
&lt;br /&gt;
===== Conflict Resolution =====&lt;br /&gt;
''' Without Merge Conflicts '''&lt;br /&gt;
Imagine two developers working on two new features, each in their own branch. If both developers are working on different parts of the codebase, or different files altogether, their changes can typically be merged back into the main codebase without any conflicts. The modifications are independent of each other and do not overlap, allowing for a seamless merge.&lt;br /&gt;
&lt;br /&gt;
'''With Merge Conflicts'''&lt;br /&gt;
Now consider a scenario where both developers are working on the same part of the code or the same file within their respective branches. When they try to merge their changes back into the main codebase, there may be conflicts where their changes overlap. Git will not know which changes to keep and which to discard, leading to a merge conflict.&lt;br /&gt;
&lt;br /&gt;
In this situation, manual intervention is needed to resolve the conflicts. The developers must review the conflicting changes, decide which to keep or how to combine them, and then commit the resolved code. Command line tools and graphic interfaces (likely built into your IDE) can assist in this process, but understanding the context of the changes and clear communication between developers is crucial for a successful resolution.&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Markdown&amp;diff=2894</id>
		<title>M1 Markdown</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Markdown&amp;diff=2894"/>
		<updated>2023-08-08T01:33:49Z</updated>

		<summary type="html">&lt;p&gt;Zach: Created page with &amp;quot;= Markdown =  Markdown is a lightweight markup language that allows you to create formatted text using a plain text editor. It uses simple symbols and characters to define dif...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Markdown =&lt;br /&gt;
&lt;br /&gt;
Markdown is a lightweight markup language that allows you to create formatted text using a plain text editor. It uses simple symbols and characters to define different elements of formatting, such as headers, lists, links, and emphasis. Markdown files have the extension &amp;lt;source enclose=&amp;quot;none&amp;quot;&amp;gt;.md&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Why Markdown? ==&lt;br /&gt;
&lt;br /&gt;
* Simplicity: Markdown's syntax is easy to learn and write, even for those unfamiliar with HTML.&lt;br /&gt;
* Portability: Markdown files are plain text, so they can be opened and edited with any text editor.&lt;br /&gt;
* Versatility: It's widely used in various platforms like GitHub, where it's commonly used for README files and comments.&lt;br /&gt;
* Versatility: Even in raw form, Markdown is designed to be readable as-is, without looking like it's been marked up with tags or formatting instructions.&lt;br /&gt;
&lt;br /&gt;
Writing in markdown allows for richly formatted text that's simple, efficient, and easily converted to HTML or other formats.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Syntax ==&lt;br /&gt;
Instead of writing a markdown guide here, there are a bunch of great resources online:&lt;br /&gt;
&lt;br /&gt;
- [https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax Github Markdown Guide]&lt;br /&gt;
- [https://www.markdownguide.org/ Markdown Guide]&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_Git&amp;diff=2893</id>
		<title>M1 Introduction to Git</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_Git&amp;diff=2893"/>
		<updated>2023-08-05T02:16:42Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Git */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''NOTE: This is an extremely simplified guide to Git meant to kickstart your work in this course. We ''strongly'' recommend you read the [[M1 Git Extended|Git Extended]] reading.'''&lt;br /&gt;
&lt;br /&gt;
== Git ==&lt;br /&gt;
&lt;br /&gt;
'''Git''' is a ''distributed version control system.'' It enables you to:&lt;br /&gt;
# Keep track of revisions to your files&lt;br /&gt;
# Push and pull your revisions to other computers or servers&lt;br /&gt;
# Collaborate with other people on the same project&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_Git&amp;diff=2892</id>
		<title>M1 Introduction to Git</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_Git&amp;diff=2892"/>
		<updated>2023-08-05T02:14:54Z</updated>

		<summary type="html">&lt;p&gt;Zach: Created page with &amp;quot;'''NOTE: This is an extremely simplified guide to Git meant to kickstart your work in this course. We ''strongly'' recommend you read the Git Extended read...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''NOTE: This is an extremely simplified guide to Git meant to kickstart your work in this course. We ''strongly'' recommend you read the [[M1 Git Extended|Git Extended]] reading.'''&lt;br /&gt;
&lt;br /&gt;
== Git ==&lt;br /&gt;
&lt;br /&gt;
'''Git''' is a ''distributed version control system.'' It enables you to:&lt;br /&gt;
# Keep track of revisions to your files&lt;br /&gt;
## Push and pull your revisions to other computers or servers&lt;br /&gt;
### Collaborate with other people on the same project&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Validation&amp;diff=2891</id>
		<title>M1 Validation</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Validation&amp;diff=2891"/>
		<updated>2023-08-05T01:51:01Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Validation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Validation ==&lt;br /&gt;
{{XKCD&lt;br /&gt;
|id=1144&lt;br /&gt;
|name=tags&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
HTML and to a lesser extent CSS are forgiving when it comes to syntactical errors in your code.  However, it is not good practice to ignore your syntax errors for a variety of reasons:&lt;br /&gt;
&lt;br /&gt;
* '''Faster and More Reliable Rendering.'''  Don't leave it up to your client's browser to decide what you meant when you made your syntax error.&lt;br /&gt;
* '''Interoperability with Compliant Browsers.'''  Although a web page may ''look'' right in your ''testing'' browser, you need to remember that there are ''lots'' of different user agents: other browsers, mobile devices, and screen readers, just to name a few.&lt;br /&gt;
* '''Accessibility.'''  Valid HTML code enables you to be confident that your page will be accessible to people with disabilities, such as the blind.&lt;br /&gt;
* '''Search Engine Optimization.''' Web sites with valid HTML syntax rank higher in search engines like Google.&lt;br /&gt;
* '''Future Proofing.'''  The W3C specification will not be made backwards-incompatible, so writing valid HTML syntax ensures that your page will work well into the future.&lt;br /&gt;
* '''More Professional.'''  No seasoned web developer will publish a page with accidental syntax errors.&lt;br /&gt;
&lt;br /&gt;
The industry standard tool for HTML and CSS syntax checking is the '''[https://validator.w3.org/ W3C Validator]'''.  '''You should ALWAYS validate your code before completing your project!'''  The Validator gives very helpful feedback to help you find and fix syntax errors.&lt;br /&gt;
&lt;br /&gt;
For more information on why it is important to validate, see [https://validator.w3.org/docs/why.html the W3C's recommendation].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== But why don't… ===&lt;br /&gt;
&lt;br /&gt;
As you play around with the validator, you may have discovered that household name sites like [https://www.google.com/ Google] and [https://www.yahoo.com/ Yahoo] do not pass the validator.  This is a deliberate act on the part of these web sites because of the following reasons:&lt;br /&gt;
&lt;br /&gt;
* '''Download Speed.'''  Sometimes, but not always, valid code adds bytes to the file size.  Sites that serve tens of thousands of requests per second are highly concerned with the increased file size.&lt;br /&gt;
* '''Interoperability with Non-Compliant Browsers.'''  ''Very'' old browsers like Netscape Navigator and Internet Explorer 5 do not respond the way that modern browsers do to the same markup.&lt;br /&gt;
&lt;br /&gt;
However, do not take these as reasons to not validate your own code.  The reasons listed in the previous section almost always outweigh the counterpoints in this section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== How to Validate Your Site ===&lt;br /&gt;
For HTML, use [https://validator.w3.org/ the HTML validator]. &lt;br /&gt;
For CSS, use [https://jigsaw.w3.org/css-validator/ the CSS validator].&lt;br /&gt;
&lt;br /&gt;
For the purposes of this course, a page is considered to pass the validator if the validator returns no errors or warnings. You will not be penalized for any &amp;quot;Info&amp;quot; type messages, but it's suggested you do your best to resolve them.&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Validation&amp;diff=2890</id>
		<title>M1 Validation</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Validation&amp;diff=2890"/>
		<updated>2023-08-05T01:50:15Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Validation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Validation ==&lt;br /&gt;
{{XKCD&lt;br /&gt;
|id=1144&lt;br /&gt;
|name=tags&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
HTML and to a lesser extent CSS are forgiving when it comes to syntactical errors in your code.  However, it is not good practice to ignore your syntax errors for a variety of reasons:&lt;br /&gt;
&lt;br /&gt;
* '''Faster and More Reliable Rendering.'''  Don't leave it up to your client's browser to decide what you meant when you made your syntax error.&lt;br /&gt;
* '''Interoperability with Compliant Browsers.'''  Although a web page may ''look'' right in your ''testing'' browser, you need to remember that there are ''lots'' of different user agents: other browsers, mobile devices, and screen readers, just to name a few.&lt;br /&gt;
* '''Accessibility.'''  Valid HTML code enables you to be confident that your page will be accessible to people with disabilities, such as the blind.&lt;br /&gt;
* '''Search Engine Optimization.''' Web sites with valid HTML syntax rank higher in search engines like Google.&lt;br /&gt;
* '''Future Proofing.'''  The W3C specification will not be made backwards-incompatible, so writing valid HTML syntax ensures that your page will work well into the future.&lt;br /&gt;
* '''More Professional.'''  No seasoned web developer will publish a page with accidental syntax errors.&lt;br /&gt;
&lt;br /&gt;
The industry standard tool for HTML and CSS syntax checking is the '''[https://validator.w3.org/ W3C Validator]'''.  '''You should ALWAYS validate your code before completing your project!'''  The Validator gives very helpful feedback to help you find and fix syntax errors.&lt;br /&gt;
&lt;br /&gt;
For more information on why it is important to validate, see [https://validator.w3.org/docs/why.html the W3C's recommendation].&lt;br /&gt;
&lt;br /&gt;
=== But why don't… ===&lt;br /&gt;
&lt;br /&gt;
As you play around with the validator, you may have discovered that household name sites like [https://www.google.com/ Google] and [https://www.yahoo.com/ Yahoo] do not pass the validator.  This is a deliberate act on the part of these web sites because of the following reasons:&lt;br /&gt;
&lt;br /&gt;
* '''Download Speed.'''  Sometimes, but not always, valid code adds bytes to the file size.  Sites that serve tens of thousands of requests per second are highly concerned with the increased file size.&lt;br /&gt;
* '''Interoperability with Non-Compliant Browsers.'''  ''Very'' old browsers like Netscape Navigator and Internet Explorer 5 do not respond the way that modern browsers do to the same markup.&lt;br /&gt;
&lt;br /&gt;
However, do not take these as reasons to not validate your own code.  The reasons listed in the previous section almost always outweigh the counterpoints in this section.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== How to Validate Your Site ===&lt;br /&gt;
For HTML, use [https://validator.w3.org/ the HTML validator]. &lt;br /&gt;
For CSS, use [https://jigsaw.w3.org/css-validator/ the CSS validator].&lt;br /&gt;
&lt;br /&gt;
For the purposes of this course, a page is considered to pass the validator if the validator returns no errors or warnings. You will not be penalized for any &amp;quot;Info&amp;quot; type messages, but it's suggested you do your best to resolve them.&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Validation&amp;diff=2889</id>
		<title>M1 Validation</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Validation&amp;diff=2889"/>
		<updated>2023-08-05T01:45:31Z</updated>

		<summary type="html">&lt;p&gt;Zach: Created page with &amp;quot;== Validation == {{XKCD |id=1144 |name=tags }}  HTML and to a lesser extent CSS are forgiving when it comes to syntactical errors in your code.  However, it is not good practi...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Validation ==&lt;br /&gt;
{{XKCD&lt;br /&gt;
|id=1144&lt;br /&gt;
|name=tags&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
HTML and to a lesser extent CSS are forgiving when it comes to syntactical errors in your code.  However, it is not good practice to ignore your syntax errors for a variety of reasons:&lt;br /&gt;
&lt;br /&gt;
* '''Faster and More Reliable Rendering.'''  Don't leave it up to your client's browser to decide what you meant when you made your syntax error.&lt;br /&gt;
* '''Interoperability with Compliant Browsers.'''  Although a web page may ''look'' right in your ''testing'' browser, you need to remember that there are ''lots'' of different user agents: other browsers, mobile devices, and screen readers, just to name a few.&lt;br /&gt;
* '''Accessibility.'''  Valid HTML code enables you to be confident that your page will be accessible to people with disabilities, such as the blind.&lt;br /&gt;
* '''Search Engine Optimization.''' Web sites with valid HTML syntax rank higher in search engines like Google.&lt;br /&gt;
* '''Future Proofing.'''  The W3C specification will not be made backwards-incompatible, so writing valid HTML syntax ensures that your page will work well into the future.&lt;br /&gt;
* '''More Professional.'''  No seasoned web developer will publish a page with accidental syntax errors.&lt;br /&gt;
&lt;br /&gt;
The industry standard tool for HTML and CSS syntax checking is the '''[https://validator.w3.org/ W3C Validator]'''.  '''You should ALWAYS validate your code before completing your project!'''  The Validator gives very helpful feedback to help you find and fix syntax errors.&lt;br /&gt;
&lt;br /&gt;
For more information on why it is important to validate, see [https://validator.w3.org/docs/why.html the W3C's recommendation].&lt;br /&gt;
&lt;br /&gt;
=== But why don't… ===&lt;br /&gt;
&lt;br /&gt;
As you play around with the validator, you may have discovered that household name sites like [https://www.google.com/ Google] and [https://www.yahoo.com/ Yahoo] do not pass the validator.  This is a deliberate act on the part of these web sites because of the following reasons:&lt;br /&gt;
&lt;br /&gt;
* '''Download Speed.'''  Sometimes, but not always, valid code adds bytes to the file size.  Sites that serve tens of thousands of requests per second are highly concerned with the increased file size.&lt;br /&gt;
* '''Interoperability with Non-Compliant Browsers.'''  ''Very'' old browsers like Netscape Navigator and Internet Explorer 5 do not respond the way that modern browsers do to the same markup.&lt;br /&gt;
&lt;br /&gt;
However, do not take these as reasons to not validate your own code.  The reasons listed in the previous section almost always outweigh the counterpoints in this section.&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Rewrite_2023&amp;diff=2888</id>
		<title>Rewrite 2023</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Rewrite_2023&amp;diff=2888"/>
		<updated>2023-08-05T01:39:26Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Directory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== 2023 Wiki reorg ==&lt;br /&gt;
I am working on a rewrite/reorg of the current wiki. In its current state, the wiki has an incredible amount of information, but I've heard from many students that it is difficult to parse and sometimes confusing as to which data is relevant. This effort serves to address some of these issues.&lt;br /&gt;
&lt;br /&gt;
In its current state, students often find it difficult to separate the assignment-critical info from supplementary content. To address this, the rewrite seperates structures each assignment like this:&lt;br /&gt;
&lt;br /&gt;
* Purpose (of module)&lt;br /&gt;
* Assignemnt&lt;br /&gt;
** Individual&lt;br /&gt;
** Group&lt;br /&gt;
&lt;br /&gt;
* Reading&lt;br /&gt;
** Required&lt;br /&gt;
** Optional&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Directory ===&lt;br /&gt;
* [[M1 Index|M1]]&lt;br /&gt;
** [[M1 Purpose|Purpose]]&lt;br /&gt;
** [[M1 Individual|Individual Assignment]]&lt;br /&gt;
** [[M1 Reading|Reading]]&lt;br /&gt;
*** Required&lt;br /&gt;
**** [[M1 Introduction to HTML|Introduction to HTML]]&lt;br /&gt;
**** [[M1 Introduction to CSS|Introduction to CSS]]&lt;br /&gt;
**** [[M1 Introduction to Git|Introduction to Git]]&lt;br /&gt;
**** [[M1 Validation|Validation]]&lt;br /&gt;
*** Supplemental&lt;br /&gt;
**** [[M1 Markdown|Markdown]]&lt;br /&gt;
**** [[M1 Accessibility|Accessibility]]&lt;br /&gt;
**** [[M1 HTML Extended|HTML Extended]]&lt;br /&gt;
**** [[M1 CSS Extended|CSS Extended]]&lt;br /&gt;
**** [[M1 Git Extended|Git Extended]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt; ''More to be added soon. The other modules will follow the same basic structure.''&amp;lt;/blockquote&amp;gt;&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Rewrite_2023&amp;diff=2887</id>
		<title>Rewrite 2023</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Rewrite_2023&amp;diff=2887"/>
		<updated>2023-08-05T01:39:03Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Directory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== 2023 Wiki reorg ==&lt;br /&gt;
I am working on a rewrite/reorg of the current wiki. In its current state, the wiki has an incredible amount of information, but I've heard from many students that it is difficult to parse and sometimes confusing as to which data is relevant. This effort serves to address some of these issues.&lt;br /&gt;
&lt;br /&gt;
In its current state, students often find it difficult to separate the assignment-critical info from supplementary content. To address this, the rewrite seperates structures each assignment like this:&lt;br /&gt;
&lt;br /&gt;
* Purpose (of module)&lt;br /&gt;
* Assignemnt&lt;br /&gt;
** Individual&lt;br /&gt;
** Group&lt;br /&gt;
&lt;br /&gt;
* Reading&lt;br /&gt;
** Required&lt;br /&gt;
** Optional&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Directory ===&lt;br /&gt;
* [[M1 Index|M1]]&lt;br /&gt;
** [[M1 Purpose|Purpose]]&lt;br /&gt;
** [[M1 Individual|Individual Assignment]]&lt;br /&gt;
** [[M1 Reading|Reading]]&lt;br /&gt;
*** Required&lt;br /&gt;
**** [[M1 Introduction to HTML|Introduction to HTML]]&lt;br /&gt;
**** [[M1 Introduction to CSS|Introduction to CSS]]&lt;br /&gt;
**** [[M1 Introduction to Git|Introduction to Git]]&lt;br /&gt;
**** [[M1 Validation|Validation]]&lt;br /&gt;
&lt;br /&gt;
*** Supplemental&lt;br /&gt;
**** [[M1 Markdown|Markdown]]&lt;br /&gt;
**** [[M1 Accessibility|Accessibility]]&lt;br /&gt;
**** [[M1 HTML Extended|HTML Extended]]&lt;br /&gt;
**** [[M1 CSS Extended|CSS Extended]]&lt;br /&gt;
**** [[M1 Git Extended|Git Extended]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt; ''More to be added soon. The other modules will follow the same basic structure.''&amp;lt;/blockquote&amp;gt;&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_CSS&amp;diff=2886</id>
		<title>M1 Introduction to CSS</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_CSS&amp;diff=2886"/>
		<updated>2023-08-05T01:38:20Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* CSS (Cascading Style Sheets) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== CSS (Cascading Style Sheets) ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Notice that we haven't said a word about how things look yet.  This is because that is what CSS is for!&lt;br /&gt;
&lt;br /&gt;
CSS stands for ''Cascading Style Sheets'', and it defines the ''appearance'' of your page.  CSS is composed of ''rules'', and each rule consists of a ''selector'' and one or more ''declarations''.  Let's see an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;css&amp;quot;&amp;gt;&lt;br /&gt;
header {&lt;br /&gt;
	color: blue;&lt;br /&gt;
	font-family: Verdana, sans-serif;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above CSS rule does three things:&lt;br /&gt;
&lt;br /&gt;
* It ''selects'' all &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;header&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; elements&lt;br /&gt;
* It ''declares'' the ''property'' '''color''' (i.e. the text color) of the selected elements to be blue&lt;br /&gt;
* It ''declares'' the ''property'' '''font-family''' (i.e. the font &amp;quot;face&amp;quot;) of the selected elements to be Verdana, or alternatively any sans-serif font if Verdana is not available&lt;br /&gt;
&lt;br /&gt;
All CSS rules follow this general format.  The following sections will discuss more detail on CSS selectors and declarations.&lt;br /&gt;
&lt;br /&gt;
=== Selectors ===&lt;br /&gt;
&lt;br /&gt;
{{DoctypeTV&lt;br /&gt;
|youtube_id=W9H95NcbTSw&lt;br /&gt;
|time=5m27s&lt;br /&gt;
|desc=CSS Selectors, Part 1&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
In the previous section's example, the most basic CSS selector was used: selecting by the ''tag name''.  To select by the ''class name'', use a period, like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;css&amp;quot;&amp;gt;&lt;br /&gt;
.info {&lt;br /&gt;
	font-weight: bold;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{DoctypeTV&lt;br /&gt;
|youtube_id=0a4r4bm1nQA&lt;br /&gt;
|time=1m29s&lt;br /&gt;
|desc=CSS Selectors, Part 2&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
A third common way to select an element is by its ID.  To select by ID, use a number sign, like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;css&amp;quot;&amp;gt;&lt;br /&gt;
#medal_table {&lt;br /&gt;
	border-collapse: collapse;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Selectors can be combined.  For example, to select all hyperlinks in any paragraph having the class &amp;quot;alert&amp;quot;, you could do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;css&amp;quot;&amp;gt;&lt;br /&gt;
p.alert a {&lt;br /&gt;
	font-style: italic;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;p.alert&amp;lt;/code&amp;gt; selects all &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; tags with the class name &amp;quot;alert&amp;quot;.  The space tells CSS to look for all descendants of such paragraphs.  Finally, the &amp;lt;code&amp;gt;a&amp;lt;/code&amp;gt; selects all &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;a&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; elements in the resulting set.&lt;br /&gt;
&lt;br /&gt;
It is also very common to use a right-angle bracket to select a ''child'' rather than a ''descendant'', the distinction being that ''descendants'' could be nested at any depth: child, grandchild, and so on, while a ''child'' must be at the next level down in the DOM.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;css&amp;quot;&amp;gt;&lt;br /&gt;
ul.fruits &amp;gt; li {&lt;br /&gt;
	text-decoration: underline;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some common CSS selectors are listed below.  For a complete list of CSS selectors, see [https://www.w3.org/TR/CSS/#selectors section 4.2 of the CSS Specification].&lt;br /&gt;
&lt;br /&gt;
* '''foo''' selects an element with tag name ''foo''&lt;br /&gt;
* '''.foo''' selects an element with the class name ''foo''&lt;br /&gt;
* '''#foo''' selects an element with the ID ''foo''&lt;br /&gt;
* '''[foo=&amp;quot;bar&amp;quot;]''' selects an element with the attribute ''foo'' whose value is ''bar''&lt;br /&gt;
* '''foo bar''' selects an element matching ''bar'' that is a descendant of an element matching ''foo''&lt;br /&gt;
* '''foo &amp;gt; bar''' selects an element matching ''car'' that is a child of an element matching ''foo''&lt;br /&gt;
* '''foo + bar''' selects an element matching ''bar'' that is the next sibling of an element matching ''foo''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Pseudo-Classes ====&lt;br /&gt;
&lt;br /&gt;
Elements can also be selected based on their current state using ''pseudo-classes''.  Pseudo-classes always begin with a colon.  For example, this is how you could change the color of all visited links on your web page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;css&amp;quot;&amp;gt;&lt;br /&gt;
a:visited {&lt;br /&gt;
	color: #99FF99; /* this example uses a hexadecimal RGB definition for the color, which allows you to&lt;br /&gt;
		mix over 16 million colors */&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some common pseudo-classes are listed below.  For a complete list, see [https://www.w3.org/TR/CSS/#selectors section 4.2 of the CSS Specification].&lt;br /&gt;
&lt;br /&gt;
* '''foo:first-child''' selects an element matching ''foo'' that is the first child of its parent (i.e., any ''foo'' that doesn't have older siblings)&lt;br /&gt;
* '''foo:last-child''' selects an element matching ''foo'' that is the last child of its parent&lt;br /&gt;
* '''foo:empty''' selects any element matching ''foo'' that has no children&lt;br /&gt;
* Pseudo-Classes for Form Elements:&lt;br /&gt;
** '''input:checked''' selects all checkboxes and radio buttons that are checked&lt;br /&gt;
* Pseudo-Classes for Hyperlink Elements:&lt;br /&gt;
** '''a:link''' selects all hyperlinks that have not been visited yet&lt;br /&gt;
** '''a:visited''' selects all hyperlinks that have been visited&lt;br /&gt;
* Pseudo-Classes for Interactive Elements (like buttons, hyperlinks, etc):&lt;br /&gt;
** '''foo:active''' selects elements matching ''foo'' that are being pressed on&lt;br /&gt;
** '''foo:hover''' selects elements matching ''foo'' that are being hovered over&lt;br /&gt;
** '''foo:focus''' selects elements matching ''foo'' that are selected (no pun intended)&lt;br /&gt;
&lt;br /&gt;
=== Properties ===&lt;br /&gt;
&lt;br /&gt;
Selectors are used to select elements that need to have styles applied to them, and properties are used to actually define those styles.  Throughout this section, you've seen properties including '''color''', '''font-family''', '''font-style''', and '''text-decoration'''.  There are dozens more properties you can define, some of which are listed below.&lt;br /&gt;
&lt;br /&gt;
For a complete list of CSS properties, see [https://www.w3.org/TR/CSS/#properties section 4.1 of the CSS Specification].&lt;br /&gt;
&lt;br /&gt;
* '''background-image''' sets the background image of an element.  Usage: &amp;lt;code&amp;gt;background-image: url(path/to/image.png);&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''background-color''' sets the background color of an element (note: the image takes precedence over the color; the color will be displayed if the image can't be found)&lt;br /&gt;
* For Tables:&lt;br /&gt;
** '''border-collapse''' removes the spacing between table cells.  Usage: &amp;lt;code&amp;gt;border-collapse: collapse;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Note: You can select td elements that are grandchildren of a table element, and then specify border properties on the td's, like this: &amp;lt;code&amp;gt;#myTable &amp;gt; tr &amp;gt; td { border: 1px solid black; }&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''border''' defines the border around an element.  Usage: &amp;lt;code&amp;gt;border: 1px dashed red;&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''border-radius''' lets you have rounded corners on your elements&lt;br /&gt;
* '''float''' makes the text of a document flow around the element.  Usage: &amp;lt;code&amp;gt;float: left;&amp;lt;/code&amp;gt; (or &amp;lt;code&amp;gt;right&amp;lt;/code&amp;gt;)&lt;br /&gt;
** '''clear''' makes an element stop wrapping around floats and instead move down to where the floats end.  Usage: &amp;lt;code&amp;gt;clear: both;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Note: If you specify multiple object in a for as floating, they will appear next to each other horizontally.&lt;br /&gt;
* '''cursor''' lets you change the type of cursor that appears then your element is in focus.  Example usage: &amp;lt;code&amp;gt;cursor: pointer;&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''font''' lets you specify the font-size, line-height, and font-family in one fell swoop.  Usage: &amp;lt;code&amp;gt;font: 14px/18px Verdana, Arial, sans-serif;&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''list-style-type''' specifies the type of number or bullet used on &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;ol&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;'s and &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;'s&lt;br /&gt;
* '''text-align''' lets you justify text on the left, center, or right&lt;br /&gt;
* '''display''' lets us specify an element as inline or block (see below), and it also enables us to &amp;quot;turn off&amp;quot; an element from being displayed on a page.  Example usage: &amp;lt;code&amp;gt;display: none;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Units ====&lt;br /&gt;
&lt;br /&gt;
Some CSS properties require that you specify numerical values for things (font-size, line-height, border-width, and so on).  CSS supports a number of units, the most common of which include:&lt;br /&gt;
&lt;br /&gt;
* '''px''', which defines a distance in pixels (relative to screen resolution).&lt;br /&gt;
* '''em''', which defines a distance relative to font size.  (Note: an ''em'' is the width of the capital letter M.  No, I'm not kidding.)&lt;br /&gt;
* '''rem''', which defines a distance relative to the font size of the root element.  Compare to '''em''', which defines a distance relative to the font size of the current element (which might have a different font size than the document root).&lt;br /&gt;
* '''pt''', which is a traditional print unit equal to 1/72 of an inch (should appear the same size on all screens regardless of resolution).&lt;br /&gt;
* '''%''', which defines a distance relative to that property of its parent element.  For the most part, you'll only use % when working with the Box Model (see below).&lt;br /&gt;
&lt;br /&gt;
=== The Box Model ===&lt;br /&gt;
&lt;br /&gt;
For the most part, all elements fall into one of two categories:&lt;br /&gt;
&lt;br /&gt;
* Inline (Examples: a, span, strong)&lt;br /&gt;
* Block (Examples: p, div, section)&lt;br /&gt;
&lt;br /&gt;
The properties we've seen thus far apply mostly to inline elements.  As it turns out, CSS has an additional set of properties that describe block elements.  These properties compose the ''box model''.&lt;br /&gt;
&lt;br /&gt;
While inline elements flow with the text, block elements stand on their own.  You can define the space between the block element and the next closest element on the page using ''margin'', the block element's border using ''border'', and the space between the block element's border and its content using ''padding'':&lt;br /&gt;
&lt;br /&gt;
[[File:Box.png]]&lt;br /&gt;
&lt;br /&gt;
For example, you could make a padded box that is centered on the page using this CSS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;css&amp;quot;&amp;gt;&lt;br /&gt;
div.box {&lt;br /&gt;
	width: 500px;&lt;br /&gt;
	margin: 0 auto; /* when two &amp;quot;arguments&amp;quot; are passed to margin or padding, the first defines top&lt;br /&gt;
		and bottom margin/padding and the second defines left and right margin/padding */&lt;br /&gt;
	padding: 25px; /* when only one &amp;quot;argument&amp;quot; is passed to margin or padding, it defines the&lt;br /&gt;
		margin/padding on all four sides */&lt;br /&gt;
	border: 1px solid black; /* the 1px defines the border-width; the solid defines the border-style;&lt;br /&gt;
		the black defines the border-color */&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is what the resulting box looks like:&lt;br /&gt;
&lt;br /&gt;
[[File:CSSBoxExample.png]]&lt;br /&gt;
&lt;br /&gt;
Note that the ''width'' defines only the ''content width''.  To compute the actual &amp;quot;width&amp;quot; of the element, you need to add the left and right padding border, and margin.&lt;br /&gt;
&lt;br /&gt;
This is only scraping the surface of the CSS box model.  All advanced web sites utilize the box model to its full extent to produce the complex layouts you have come to expect on the internet.  For more information on the CSS box model, read [https://www.w3.org/TR/css3-box/ the W3C specification].&lt;br /&gt;
&lt;br /&gt;
=== Typography ===&lt;br /&gt;
&lt;br /&gt;
Traditionally, Web developers were limited to a small subset of fonts that were commonly installed on all computers:&lt;br /&gt;
&lt;br /&gt;
* Andale Mono&lt;br /&gt;
* Arial&lt;br /&gt;
* Arial Black&lt;br /&gt;
* Comic Sans MS&lt;br /&gt;
* Courier New&lt;br /&gt;
* Georgia&lt;br /&gt;
* Impact&lt;br /&gt;
* Times New Roman&lt;br /&gt;
* Trebuchet MS&lt;br /&gt;
* Verdana&lt;br /&gt;
* Webdings&lt;br /&gt;
&lt;br /&gt;
That was it.  Incredibly limiting.&lt;br /&gt;
&lt;br /&gt;
However, fonts other than these are used widely on the Web.  How?  CSS has evolved to the point where it now allows you to upload a font to your server, and use that font on your site, or even include CSS from another server that adds the fonts you want. One excellent resource for a wide variety of &lt;br /&gt;
fast, appropriately-licensed fonts is [https://fonts.google.com/ Google Fonts].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Using HTML and CSS in your Web Page ==&lt;br /&gt;
&lt;br /&gt;
Recall that HTML defines the ''content'' of your page, while CSS defines the ''appearance''.&lt;br /&gt;
&lt;br /&gt;
Most of the HTML you write will be in the &amp;lt;code&amp;gt;&amp;lt;body&amp;gt;&amp;lt;/code&amp;gt; tag, because, naturally, this is where the ''content'' of your page should reside.  CSS, on the other hand, is supplemental to the content, and so it should be included in the &amp;lt;code&amp;gt;&amp;lt;head&amp;gt;&amp;lt;/code&amp;gt; tag, as shown in the following section.&lt;br /&gt;
&lt;br /&gt;
=== How to Include CSS ===&lt;br /&gt;
&lt;br /&gt;
There are three options for using CSS in your web page:&lt;br /&gt;
&lt;br /&gt;
# Loading external stylesheets&lt;br /&gt;
# Embedding stylesheets in the document&lt;br /&gt;
# Inline styles using the style attribute&lt;br /&gt;
&lt;br /&gt;
The first option is almost always preferred in production applications for the following reasons:&lt;br /&gt;
&lt;br /&gt;
* Browsers can cache external stylesheets, so once they've loaded the stylesheet once, they won't have to load it again, making future pages load faster and reducing requests to your server&lt;br /&gt;
* External stylesheets are more modular; that is, they can be included in multiple pages on your web site without the need for copying and pasting embedded stylesheets&lt;br /&gt;
&lt;br /&gt;
To include external stylesheets in your document, place the following empty HTML tag in your &amp;lt;code&amp;gt;&amp;lt;head&amp;gt;&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; type=&amp;quot;text/css&amp;quot; href=&amp;quot;path/to/stylesheet.css&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
It may be convenient during development to use embedded stylesheets, because then you don't have to click back and forth between files in your IDE and clear your browser cache.  You may place embedded stylesheets in a &amp;lt;code&amp;gt;&amp;lt;style&amp;gt;&amp;lt;/code&amp;gt; tag, also in your &amp;lt;code&amp;gt;&amp;lt;head&amp;gt;&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;style type=&amp;quot;text/css&amp;quot;&amp;gt;&lt;br /&gt;
styles {&lt;br /&gt;
	go: here;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/style&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For a variety of reasons, inline styles should almost always be avoided.  Instead of using inline styles, give your element a CSS class, and assign styles to that class in your stylesheet:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;css&amp;quot;&amp;gt;&lt;br /&gt;
p.notice {&lt;br /&gt;
	color: blue;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p class=&amp;quot;notice&amp;quot;&amp;gt;Well done using classes instead of inline styles!&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Just so you know it when you see it, the following example shows the usage of inline styles, which are declared using the '''style''' attribute.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p style=&amp;quot;color:red;&amp;quot;&amp;gt;You'd better think twice about using inline styles.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Quick and Easy Page Layout ===&lt;br /&gt;
&lt;br /&gt;
I like to use the following code when I just want a simple, aesthetically pleasing web page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
&amp;lt;meta charset=&amp;quot;utf-8&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;title&amp;gt;My Web Page&amp;lt;/title&amp;gt;&lt;br /&gt;
&amp;lt;style type=&amp;quot;text/css&amp;quot;&amp;gt;&lt;br /&gt;
body{&lt;br /&gt;
	width: 760px; /* how wide to make your web page */&lt;br /&gt;
	background-color: teal; /* what color to make the background */&lt;br /&gt;
	margin: 0 auto;&lt;br /&gt;
	padding: 0;&lt;br /&gt;
	font:12px/16px Verdana, sans-serif; /* default font */&lt;br /&gt;
}&lt;br /&gt;
div#main{&lt;br /&gt;
	background-color: #FFF;&lt;br /&gt;
	margin: 0;&lt;br /&gt;
	padding: 10px;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/style&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&amp;lt;div id=&amp;quot;main&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- CONTENT HERE --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Put your document where the &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;!-- CONTENT HERE --&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; is.  Your page will go instantly from dull-looking to presentable. ;-)&lt;br /&gt;
&lt;br /&gt;
=== The HTML5 Shiv ===&lt;br /&gt;
&lt;br /&gt;
Some browsers (*cough cough* IE &amp;lt; version 9) do strange things when you apply CSS styles to the newest HTML elements that were introduced with HTML5.  Fortunately, there is a painless solution.  Simply include the following code in your '''&amp;lt;head&amp;gt;''' tag:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!--[if lt IE 9]&amp;gt;&lt;br /&gt;
&amp;lt;script src=&amp;quot;https://html5shiv.googlecode.com/svn/trunk/html5.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;![endif]--&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This so-called '''HTML5 Shiv''' will make older versions of Internet Explorer render your pages more closely to how modern browsers do.&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_CSS&amp;diff=2885</id>
		<title>M1 Introduction to CSS</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_CSS&amp;diff=2885"/>
		<updated>2023-08-05T01:35:57Z</updated>

		<summary type="html">&lt;p&gt;Zach: Created page with &amp;quot;== CSS (Cascading Style Sheets) ==   Notice that we haven't said a word about how things look yet.  This is because that is what CSS is for!  CSS stands for ''Cascading Style...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== CSS (Cascading Style Sheets) ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Notice that we haven't said a word about how things look yet.  This is because that is what CSS is for!&lt;br /&gt;
&lt;br /&gt;
CSS stands for ''Cascading Style Sheets'', and it defines the ''appearance'' of your page.  CSS is composed of ''rules'', and each rule consists of a ''selector'' and one or more ''declarations''.  Let's see an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;css&amp;quot;&amp;gt;&lt;br /&gt;
header {&lt;br /&gt;
	color: blue;&lt;br /&gt;
	font-family: Verdana, sans-serif;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above CSS rule does three things:&lt;br /&gt;
&lt;br /&gt;
* It ''selects'' all &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;header&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; elements&lt;br /&gt;
* It ''declares'' the ''property'' '''color''' (i.e. the text color) of the selected elements to be blue&lt;br /&gt;
* It ''declares'' the ''property'' '''font-family''' (i.e. the font &amp;quot;face&amp;quot;) of the selected elements to be Verdana, or alternatively any sans-serif font if Verdana is not available&lt;br /&gt;
&lt;br /&gt;
All CSS rules follow this general format.  The following sections will discuss more detail on CSS selectors and declarations.&lt;br /&gt;
&lt;br /&gt;
=== Selectors ===&lt;br /&gt;
&lt;br /&gt;
{{DoctypeTV&lt;br /&gt;
|youtube_id=W9H95NcbTSw&lt;br /&gt;
|time=5m27s&lt;br /&gt;
|desc=CSS Selectors, Part 1&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
In the previous section's example, the most basic CSS selector was used: selecting by the ''tag name''.  To select by the ''class name'', use a period, like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;css&amp;quot;&amp;gt;&lt;br /&gt;
.info {&lt;br /&gt;
	font-weight: bold;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{DoctypeTV&lt;br /&gt;
|youtube_id=0a4r4bm1nQA&lt;br /&gt;
|time=1m29s&lt;br /&gt;
|desc=CSS Selectors, Part 2&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
A third common way to select an element is by its ID.  To select by ID, use a number sign, like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;css&amp;quot;&amp;gt;&lt;br /&gt;
#medal_table {&lt;br /&gt;
	border-collapse: collapse;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Selectors can be combined.  For example, to select all hyperlinks in any paragraph having the class &amp;quot;alert&amp;quot;, you could do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;css&amp;quot;&amp;gt;&lt;br /&gt;
p.alert a {&lt;br /&gt;
	font-style: italic;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;p.alert&amp;lt;/code&amp;gt; selects all &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; tags with the class name &amp;quot;alert&amp;quot;.  The space tells CSS to look for all descendants of such paragraphs.  Finally, the &amp;lt;code&amp;gt;a&amp;lt;/code&amp;gt; selects all &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;a&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; elements in the resulting set.&lt;br /&gt;
&lt;br /&gt;
It is also very common to use a right-angle bracket to select a ''child'' rather than a ''descendant'', the distinction being that ''descendants'' could be nested at any depth: child, grandchild, and so on, while a ''child'' must be at the next level down in the DOM.  For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;css&amp;quot;&amp;gt;&lt;br /&gt;
ul.fruits &amp;gt; li {&lt;br /&gt;
	text-decoration: underline;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some common CSS selectors are listed below.  For a complete list of CSS selectors, see [https://www.w3.org/TR/CSS/#selectors section 4.2 of the CSS Specification].&lt;br /&gt;
&lt;br /&gt;
* '''foo''' selects an element with tag name ''foo''&lt;br /&gt;
* '''.foo''' selects an element with the class name ''foo''&lt;br /&gt;
* '''#foo''' selects an element with the ID ''foo''&lt;br /&gt;
* '''[foo=&amp;quot;bar&amp;quot;]''' selects an element with the attribute ''foo'' whose value is ''bar''&lt;br /&gt;
* '''foo bar''' selects an element matching ''bar'' that is a descendant of an element matching ''foo''&lt;br /&gt;
* '''foo &amp;gt; bar''' selects an element matching ''car'' that is a child of an element matching ''foo''&lt;br /&gt;
* '''foo + bar''' selects an element matching ''bar'' that is the next sibling of an element matching ''foo''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Pseudo-Classes ====&lt;br /&gt;
&lt;br /&gt;
Elements can also be selected based on their current state using ''pseudo-classes''.  Pseudo-classes always begin with a colon.  For example, this is how you could change the color of all visited links on your web page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;css&amp;quot;&amp;gt;&lt;br /&gt;
a:visited {&lt;br /&gt;
	color: #99FF99; /* this example uses a hexadecimal RGB definition for the color, which allows you to&lt;br /&gt;
		mix over 16 million colors */&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some common pseudo-classes are listed below.  For a complete list, see [https://www.w3.org/TR/CSS/#selectors section 4.2 of the CSS Specification].&lt;br /&gt;
&lt;br /&gt;
* '''foo:first-child''' selects an element matching ''foo'' that is the first child of its parent (i.e., any ''foo'' that doesn't have older siblings)&lt;br /&gt;
* '''foo:last-child''' selects an element matching ''foo'' that is the last child of its parent&lt;br /&gt;
* '''foo:empty''' selects any element matching ''foo'' that has no children&lt;br /&gt;
* Pseudo-Classes for Form Elements:&lt;br /&gt;
** '''input:checked''' selects all checkboxes and radio buttons that are checked&lt;br /&gt;
* Pseudo-Classes for Hyperlink Elements:&lt;br /&gt;
** '''a:link''' selects all hyperlinks that have not been visited yet&lt;br /&gt;
** '''a:visited''' selects all hyperlinks that have been visited&lt;br /&gt;
* Pseudo-Classes for Interactive Elements (like buttons, hyperlinks, etc):&lt;br /&gt;
** '''foo:active''' selects elements matching ''foo'' that are being pressed on&lt;br /&gt;
** '''foo:hover''' selects elements matching ''foo'' that are being hovered over&lt;br /&gt;
** '''foo:focus''' selects elements matching ''foo'' that are selected (no pun intended)&lt;br /&gt;
&lt;br /&gt;
=== Properties ===&lt;br /&gt;
&lt;br /&gt;
Selectors are used to select elements that need to have styles applied to them, and properties are used to actually define those styles.  Throughout this section, you've seen properties including '''color''', '''font-family''', '''font-style''', and '''text-decoration'''.  There are dozens more properties you can define, some of which are listed below.&lt;br /&gt;
&lt;br /&gt;
For a complete list of CSS properties, see [https://www.w3.org/TR/CSS/#properties section 4.1 of the CSS Specification].&lt;br /&gt;
&lt;br /&gt;
* '''background-image''' sets the background image of an element.  Usage: &amp;lt;code&amp;gt;background-image: url(path/to/image.png);&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''background-color''' sets the background color of an element (note: the image takes precedence over the color; the color will be displayed if the image can't be found)&lt;br /&gt;
* For Tables:&lt;br /&gt;
** '''border-collapse''' removes the spacing between table cells.  Usage: &amp;lt;code&amp;gt;border-collapse: collapse;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Note: You can select td elements that are grandchildren of a table element, and then specify border properties on the td's, like this: &amp;lt;code&amp;gt;#myTable &amp;gt; tr &amp;gt; td { border: 1px solid black; }&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''border''' defines the border around an element.  Usage: &amp;lt;code&amp;gt;border: 1px dashed red;&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''border-radius''' lets you have rounded corners on your elements&lt;br /&gt;
* '''float''' makes the text of a document flow around the element.  Usage: &amp;lt;code&amp;gt;float: left;&amp;lt;/code&amp;gt; (or &amp;lt;code&amp;gt;right&amp;lt;/code&amp;gt;)&lt;br /&gt;
** '''clear''' makes an element stop wrapping around floats and instead move down to where the floats end.  Usage: &amp;lt;code&amp;gt;clear: both;&amp;lt;/code&amp;gt;&lt;br /&gt;
** Note: If you specify multiple object in a for as floating, they will appear next to each other horizontally.&lt;br /&gt;
* '''cursor''' lets you change the type of cursor that appears then your element is in focus.  Example usage: &amp;lt;code&amp;gt;cursor: pointer;&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''font''' lets you specify the font-size, line-height, and font-family in one fell swoop.  Usage: &amp;lt;code&amp;gt;font: 14px/18px Verdana, Arial, sans-serif;&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''list-style-type''' specifies the type of number or bullet used on &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;ol&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;'s and &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;'s&lt;br /&gt;
* '''text-align''' lets you justify text on the left, center, or right&lt;br /&gt;
* '''display''' lets us specify an element as inline or block (see below), and it also enables us to &amp;quot;turn off&amp;quot; an element from being displayed on a page.  Example usage: &amp;lt;code&amp;gt;display: none;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Units ====&lt;br /&gt;
&lt;br /&gt;
Some CSS properties require that you specify numerical values for things (font-size, line-height, border-width, and so on).  CSS supports a number of units, the most common of which include:&lt;br /&gt;
&lt;br /&gt;
* '''px''', which defines a distance in pixels (relative to screen resolution).&lt;br /&gt;
* '''em''', which defines a distance relative to font size.  (Note: an ''em'' is the width of the capital letter M.  No, I'm not kidding.)&lt;br /&gt;
* '''rem''', which defines a distance relative to the font size of the root element.  Compare to '''em''', which defines a distance relative to the font size of the current element (which might have a different font size than the document root).&lt;br /&gt;
* '''pt''', which is a traditional print unit equal to 1/72 of an inch (should appear the same size on all screens regardless of resolution).&lt;br /&gt;
* '''%''', which defines a distance relative to that property of its parent element.  For the most part, you'll only use % when working with the Box Model (see below).&lt;br /&gt;
&lt;br /&gt;
=== The Box Model ===&lt;br /&gt;
&lt;br /&gt;
For the most part, all elements fall into one of two categories:&lt;br /&gt;
&lt;br /&gt;
* Inline (Examples: a, span, strong)&lt;br /&gt;
* Block (Examples: p, div, section)&lt;br /&gt;
&lt;br /&gt;
The properties we've seen thus far apply mostly to inline elements.  As it turns out, CSS has an additional set of properties that describe block elements.  These properties compose the ''box model''.&lt;br /&gt;
&lt;br /&gt;
While inline elements flow with the text, block elements stand on their own.  You can define the space between the block element and the next closest element on the page using ''margin'', the block element's border using ''border'', and the space between the block element's border and its content using ''padding'':&lt;br /&gt;
&lt;br /&gt;
[[File:Box.png]]&lt;br /&gt;
&lt;br /&gt;
For example, you could make a padded box that is centered on the page using this CSS:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;css&amp;quot;&amp;gt;&lt;br /&gt;
div.box {&lt;br /&gt;
	width: 500px;&lt;br /&gt;
	margin: 0 auto; /* when two &amp;quot;arguments&amp;quot; are passed to margin or padding, the first defines top&lt;br /&gt;
		and bottom margin/padding and the second defines left and right margin/padding */&lt;br /&gt;
	padding: 25px; /* when only one &amp;quot;argument&amp;quot; is passed to margin or padding, it defines the&lt;br /&gt;
		margin/padding on all four sides */&lt;br /&gt;
	border: 1px solid black; /* the 1px defines the border-width; the solid defines the border-style;&lt;br /&gt;
		the black defines the border-color */&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is what the resulting box looks like:&lt;br /&gt;
&lt;br /&gt;
[[File:CSSBoxExample.png]]&lt;br /&gt;
&lt;br /&gt;
Note that the ''width'' defines only the ''content width''.  To compute the actual &amp;quot;width&amp;quot; of the element, you need to add the left and right padding border, and margin.&lt;br /&gt;
&lt;br /&gt;
This is only scraping the surface of the CSS box model.  All advanced web sites utilize the box model to its full extent to produce the complex layouts you have come to expect on the internet.  For more information on the CSS box model, read [https://www.w3.org/TR/css3-box/ the W3C specification].&lt;br /&gt;
&lt;br /&gt;
=== Typography ===&lt;br /&gt;
&lt;br /&gt;
Traditionally, Web developers were limited to a small subset of fonts that were commonly installed on all computers:&lt;br /&gt;
&lt;br /&gt;
* Andale Mono&lt;br /&gt;
* Arial&lt;br /&gt;
* Arial Black&lt;br /&gt;
* Comic Sans MS&lt;br /&gt;
* Courier New&lt;br /&gt;
* Georgia&lt;br /&gt;
* Impact&lt;br /&gt;
* Times New Roman&lt;br /&gt;
* Trebuchet MS&lt;br /&gt;
* Verdana&lt;br /&gt;
* Webdings&lt;br /&gt;
&lt;br /&gt;
That was it.  Incredibly limiting.&lt;br /&gt;
&lt;br /&gt;
However, fonts other than these are used widely on the Web.  How?  CSS has evolved to the point where it now allows you to upload a font to your server, and use that font on your site, or even include CSS from another server that adds the fonts you want. One excellent resource for a wide variety of fast, appropriately-licensed fonts is [https://fonts.google.com/ Google Fonts].&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_HTML&amp;diff=2884</id>
		<title>M1 Introduction to HTML</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_HTML&amp;diff=2884"/>
		<updated>2023-08-05T01:20:08Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* HTML */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== HTML ==&lt;br /&gt;
&lt;br /&gt;
=== HTML? ===&lt;br /&gt;
&lt;br /&gt;
HTML, which stands for HyperText Markup Language, is the standard language used to create webpages. It describes the structure and content of a webpage. HTML uses a system of tags and attributes to define elements on the page. These elements can be things like headings, paragraphs, links, images, lists, tables, forms, and many more. Each of these elements has a specific tag that describes what it is and helps the browser know how to display it.&lt;br /&gt;
&lt;br /&gt;
Here's a very basic example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
  &amp;lt;head&amp;gt;&lt;br /&gt;
    &amp;lt;title&amp;gt;My First Web Page&amp;lt;/title&amp;gt;&lt;br /&gt;
  &amp;lt;/head&amp;gt;&lt;br /&gt;
  &amp;lt;body&amp;gt;&lt;br /&gt;
    &amp;lt;h1&amp;gt;Welcome to My Website!&amp;lt;/h1&amp;gt;&lt;br /&gt;
    &amp;lt;p&amp;gt;This is a paragraph of text.&amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Image will go here'''&lt;br /&gt;
&lt;br /&gt;
In this example:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;!DOCTYPE html&amp;gt;&amp;lt;/source&amp;gt; The page begins with a DOCTYPE declaration. This is a mandatory part of a web page, and it tells the browser what version of HTML to use when rendering your page. In this case, the browser should use HTML 5.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;html&amp;gt;&amp;lt;/source&amp;gt; tag is the root of an HTML document.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;head&amp;gt;&amp;lt;/source&amp;gt; tag contains meta-information about the document. This can include the title, character set declarations, CSS style definitions, and more.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/source&amp;gt; tag is the title of the document and is displayed in the browser's title bar or tab.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;body&amp;gt;&amp;lt;/source&amp;gt; tag contains the content of the document, such as text, hyperlinks, images, tables, lists, etc. When you visit a website, the content you see is rendered in the body.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt; tag defines a top-level heading, and the &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/source&amp;gt; tag defines a paragraph.&lt;br /&gt;
&lt;br /&gt;
In essence, HTML gives the webpage its basic structure and content; without it, a webpage can't exist.&lt;br /&gt;
&lt;br /&gt;
''You can view a web page's source code in your browser; in Firefox, the keyboard shortcut is Ctrl-U (or Command-U), and in Chrome, it is Alt-Ctrl-U (or Option-Command-U).''&lt;br /&gt;
&lt;br /&gt;
=== Tags ===&lt;br /&gt;
&lt;br /&gt;
Tags in HTML are special words or symbols enclosed in angle brackets (&amp;lt; &amp;gt;) that define the structure and formatting of elements within a web page. They act as instructions to the web browser on how to display and interpret the content. Opening tags, such as &amp;lt;tagname&amp;gt;, mark the beginning of an element, while closing tags, like &amp;lt;/tagname&amp;gt;, denote the end. Tags are like containers that hold different types of content, such as text, images, links, or other elements, and they play a crucial role in creating the structure and appearance of a webpage.&lt;br /&gt;
&lt;br /&gt;
Here are some of the most common HTML tags you will encounter. Get to know these well. For more information on how to use a given tag, [https://developer.mozilla.org/en-US/docs/Web/HTML/Element|the MDN docs] are an incredible resource.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:15%&amp;quot; | Tag&lt;br /&gt;
! style=&amp;quot;width:85%&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;html&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines the root element of an HTML document.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;head&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Contains metadata and information about the HTML document. (docs)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Sets the title of the document, displayed in the browser's title bar or tab. (docs)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;body&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents the main content of the HTML document.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt; to &amp;lt;source lang=&amp;quot;html&amp;quot;enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines headings of different levels, from the most important (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt;) to the least (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents a paragraph of text.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;a&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates a hyperlink to another web page, file, or a specific location within the same page.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;img&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Inserts an image into the HTML document.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents an unordered list (a bulleted list).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ol&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents an ordered list (a numbered list).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;li&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines an item in a list (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;/source&amp;gt; or &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ol&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;table&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents tabular data organized into rows and columns.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a row within a table.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;td&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a cell within a table row (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;th&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a header cell within a table row (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;div&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a division or a container for other elements.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;span&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines an inline container for a small section of HTML.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;form&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates an interactive form for user input.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;input&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates an input field for user data entry.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;button&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates a clickable button.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;textarea&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates a multiline text input field.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Built-in Functionality ===&lt;br /&gt;
&lt;br /&gt;
While HTML primarily focuses on structure and content, some HTML tags come with built-in functionality that extends beyond that. These tags incorporate specific behaviors or interactivity into the elements they define. For example, the &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;a&amp;gt;&amp;lt;/source&amp;gt; tag creates hyperlinks, allowing users to navigate to different web pages or sections within the same page. The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;form&amp;gt;&amp;lt;/source&amp;gt; tag enables the creation of interactive forms to gather user input, and the &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;input&amp;gt;&amp;lt;/source&amp;gt; tag provides various types of input fields like text boxes or checkboxes.&lt;br /&gt;
&lt;br /&gt;
To learn about less common tags with fun built-in functionality, see the optional reading, [[M1 HTML Extended|HTML Extended]]. I also encourage you to spend some time exploring [https://developer.mozilla.org/en-US/docs/Web/HTML/Element|the MDN docs].&lt;br /&gt;
&lt;br /&gt;
=== Default Styling ===&lt;br /&gt;
&lt;br /&gt;
When rendering HTML documents, web browsers apply default styles to each HTML element. These default styles determine how the elements are displayed visually, such as their font, color, size, spacing, and positioning. However, it's important to note that default styles may vary slightly between different browsers.&lt;br /&gt;
&lt;br /&gt;
Browsers have their own predefined stylesheets, often referred to as user agent stylesheets, which dictate the initial appearance of HTML elements. This means that even without explicitly applying any styles, elements will still have some visual presentation based on these default styles.&lt;br /&gt;
&lt;br /&gt;
See [M1 Introduction to CSS|Introduction to CSS] for a guide to styling elements.&lt;br /&gt;
&lt;br /&gt;
=== Nodes ===&lt;br /&gt;
&lt;br /&gt;
Where a tag is a syntax used in HTML to define elements, a node is a conceptual representation of an element within the Document Object Model (DOM) hierarchy. In simpler terms, a tag is the markup language used to define an element, whereas a node is an object that represents that element within the structured model of the HTML document.&lt;br /&gt;
&lt;br /&gt;
Nodes form a hierarchical structure known as the Document Object Model (DOM). The DOM represents the HTML document as a tree-like structure, where each node has a relationship with its parent, children, and siblings. The topmost node in the DOM is the document node, representing the entire HTML document.&lt;br /&gt;
&lt;br /&gt;
Here are the main types of nodes commonly encountered in HTML:&lt;br /&gt;
&lt;br /&gt;
==== Element Nodes ====&lt;br /&gt;
&lt;br /&gt;
These nodes represent HTML elements and are the most common type. They correspond to the opening and closing tags of an HTML element. For example, &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;div&amp;gt;...&amp;lt;/div&amp;gt;&amp;lt;/source&amp;gt;, &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;p&amp;gt;...&amp;lt;/p&amp;gt;&amp;lt;/source&amp;gt;, &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;...&amp;lt;/h1&amp;gt;&amp;lt;/source&amp;gt; are all element nodes. Element nodes can contain child nodes, such as other elements, text nodes, or comment nodes.&lt;br /&gt;
&lt;br /&gt;
==== Text Nodes ====&lt;br /&gt;
&lt;br /&gt;
Text nodes represent the textual content within an HTML element. They can contain plain text, including spaces, line breaks, or any other characters. For instance, in the element&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&amp;lt;p&amp;gt;Hello, &amp;lt;strong&amp;gt;world!&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the text node would contain &amp;quot;Hello,&amp;quot; and &amp;quot;world!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== Attribute Nodes ====&lt;br /&gt;
&lt;br /&gt;
These nodes represent the attributes of an HTML element. An element can have multiple attributes like id, class, src, etc. Attribute nodes contain the name and value of the attribute. For example, in the element&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&amp;lt;img src=&amp;quot;image.jpg&amp;quot; alt=&amp;quot;An image&amp;quot; /&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the `src` and `alt` attributes would be represented as attribute nodes.&lt;br /&gt;
&lt;br /&gt;
==== Comment Nodes ====&lt;br /&gt;
&lt;br /&gt;
Comment nodes represent HTML comments within the document. They are used to add explanatory or descriptive notes that are not displayed in the rendered output. Comment nodes start with &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;!--&amp;lt;/source&amp;gt;and end with &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;--&amp;gt;&amp;lt;/source&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&amp;lt;!-- This is a comment --&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== The High School Analogy ===&lt;br /&gt;
In more ways than not, HTML can be thought of as a markup language for five-paragraph essays that you wrote in history class in high school. &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;blockquote&amp;gt;&amp;lt;/source&amp;gt; is used to denote long quotations; &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt; through &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;/source&amp;gt; denote the outline; &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/source&amp;gt; denotes new paragraphs; &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;figure&amp;gt;&amp;lt;/source&amp;gt; and &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;figcaption&amp;gt;&amp;lt;/source&amp;gt; represent exhibits; &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;section&amp;gt;&amp;lt;/source&amp;gt; could represent chapters if you were writing a longer report; and so on.&lt;br /&gt;
Take home message: HTML defines the content of your page. Use it to its full ability.&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_HTML&amp;diff=2883</id>
		<title>M1 Introduction to HTML</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_HTML&amp;diff=2883"/>
		<updated>2023-08-05T01:14:08Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* HTML? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== HTML ==&lt;br /&gt;
&lt;br /&gt;
=== HTML? ===&lt;br /&gt;
&lt;br /&gt;
HTML, which stands for HyperText Markup Language, is the standard language used to create webpages. It describes the structure and content of a webpage. HTML uses a system of tags and attributes to define elements on the page. These elements can be things like headings, paragraphs, links, images, lists, tables, forms, and many more. Each of these elements has a specific tag that describes what it is and helps the browser know how to display it.&lt;br /&gt;
&lt;br /&gt;
Here's a very basic example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
  &amp;lt;head&amp;gt;&lt;br /&gt;
    &amp;lt;title&amp;gt;My First Web Page&amp;lt;/title&amp;gt;&lt;br /&gt;
  &amp;lt;/head&amp;gt;&lt;br /&gt;
  &amp;lt;body&amp;gt;&lt;br /&gt;
    &amp;lt;h1&amp;gt;Welcome to My Website!&amp;lt;/h1&amp;gt;&lt;br /&gt;
    &amp;lt;p&amp;gt;This is a paragraph of text.&amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Image will go here'''&lt;br /&gt;
&lt;br /&gt;
In this example:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;!DOCTYPE html&amp;gt;&amp;lt;/source&amp;gt; The page begins with a DOCTYPE declaration. This is a mandatory part of a web page, and it tells the browser what version of HTML to use when rendering your page. In this case, the browser should use HTML 5.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;html&amp;gt;&amp;lt;/source&amp;gt; tag is the root of an HTML document.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;head&amp;gt;&amp;lt;/source&amp;gt; tag contains meta-information about the document. This can include the title, character set declarations, CSS style definitions, and more.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/source&amp;gt; tag is the title of the document and is displayed in the browser's title bar or tab.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;body&amp;gt;&amp;lt;/source&amp;gt; tag contains the content of the document, such as text, hyperlinks, images, tables, lists, etc. When you visit a website, the content you see is rendered in the body.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt; tag defines a top-level heading, and the &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/source&amp;gt; tag defines a paragraph.&lt;br /&gt;
&lt;br /&gt;
In essence, HTML gives the webpage its basic structure and content; without it, a webpage can't exist.&lt;br /&gt;
&lt;br /&gt;
''You can view a web page's source code in your browser; in Firefox, the keyboard shortcut is Ctrl-U (or Command-U), and in Chrome, it is Alt-Ctrl-U (or Option-Command-U).''&lt;br /&gt;
&lt;br /&gt;
=== Tags ===&lt;br /&gt;
&lt;br /&gt;
Tags in HTML are special words or symbols enclosed in angle brackets (&amp;lt; &amp;gt;) that define the structure and formatting of elements within a web page. They act as instructions to the web browser on how to display and interpret the content. Opening tags, such as &amp;lt;tagname&amp;gt;, mark the beginning of an element, while closing tags, like &amp;lt;/tagname&amp;gt;, denote the end. Tags are like containers that hold different types of content, such as text, images, links, or other elements, and they play a crucial role in creating the structure and appearance of a webpage.&lt;br /&gt;
&lt;br /&gt;
Here are some of the most common HTML tags you will encounter. Get to know these well. For more information on how to use a given tag, [https://developer.mozilla.org/en-US/docs/Web/HTML/Element|the MDN docs] are an incredible resource.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:15%&amp;quot; | Tag&lt;br /&gt;
! style=&amp;quot;width:85%&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;html&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines the root element of an HTML document.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;head&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Contains metadata and information about the HTML document. (docs)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Sets the title of the document, displayed in the browser's title bar or tab. (docs)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;body&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents the main content of the HTML document.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt; to &amp;lt;source lang=&amp;quot;html&amp;quot;enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines headings of different levels, from the most important (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt;) to the least (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents a paragraph of text.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;a&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates a hyperlink to another web page, file, or a specific location within the same page.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;img&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Inserts an image into the HTML document.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents an unordered list (a bulleted list).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ol&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents an ordered list (a numbered list).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;li&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines an item in a list (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;/source&amp;gt; or &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ol&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;table&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents tabular data organized into rows and columns.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a row within a table.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;td&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a cell within a table row (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;th&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a header cell within a table row (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;div&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a division or a container for other elements.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;span&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines an inline container for a small section of HTML.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;form&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates an interactive form for user input.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;input&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates an input field for user data entry.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;button&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates a clickable button.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;textarea&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates a multiline text input field.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Built-in Functionality ===&lt;br /&gt;
&lt;br /&gt;
While HTML primarily focuses on structure and content, some HTML tags come with built-in functionality that extends beyond that. These tags incorporate specific behaviors or interactivity into the elements they define. For example, the &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;a&amp;gt;&amp;lt;/source&amp;gt; tag creates hyperlinks, allowing users to navigate to different web pages or sections within the same page. The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;form&amp;gt;&amp;lt;/source&amp;gt; tag enables the creation of interactive forms to gather user input, and the &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;input&amp;gt;&amp;lt;/source&amp;gt; tag provides various types of input fields like text boxes or checkboxes.&lt;br /&gt;
&lt;br /&gt;
To learn about less common tags with fun built-in functionality, see the optional reading, [[M1 HTML Extended|HTML Extended]]. I also encourage you to spend some time exploring [https://developer.mozilla.org/en-US/docs/Web/HTML/Element|the MDN docs].&lt;br /&gt;
&lt;br /&gt;
=== Default Styling ===&lt;br /&gt;
&lt;br /&gt;
When rendering HTML documents, web browsers apply default styles to each HTML element. These default styles determine how the elements are displayed visually, such as their font, color, size, spacing, and positioning. However, it's important to note that default styles may vary slightly between different browsers.&lt;br /&gt;
&lt;br /&gt;
Browsers have their own predefined stylesheets, often referred to as user agent stylesheets, which dictate the initial appearance of HTML elements. This means that even without explicitly applying any styles, elements will still have some visual presentation based on these default styles.&lt;br /&gt;
&lt;br /&gt;
See [M1 Introduction to CSS|Introduction to CSS] for a guide to styling elements.&lt;br /&gt;
&lt;br /&gt;
=== Nodes ===&lt;br /&gt;
&lt;br /&gt;
Where a tag is a syntax used in HTML to define elements, a node is a conceptual representation of an element within the Document Object Model (DOM) hierarchy. In simpler terms, a tag is the markup language used to define an element, whereas a node is an object that represents that element within the structured model of the HTML document.&lt;br /&gt;
&lt;br /&gt;
Nodes form a hierarchical structure known as the Document Object Model (DOM). The DOM represents the HTML document as a tree-like structure, where each node has a relationship with its parent, children, and siblings. The topmost node in the DOM is the document node, representing the entire HTML document.&lt;br /&gt;
&lt;br /&gt;
Here are the main types of nodes commonly encountered in HTML:&lt;br /&gt;
&lt;br /&gt;
==== Element Nodes ====&lt;br /&gt;
&lt;br /&gt;
These nodes represent HTML elements and are the most common type. They correspond to the opening and closing tags of an HTML element. For example, &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;div&amp;gt;...&amp;lt;/div&amp;gt;&amp;lt;/source&amp;gt;, &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;p&amp;gt;...&amp;lt;/p&amp;gt;&amp;lt;/source&amp;gt;, &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;...&amp;lt;/h1&amp;gt;&amp;lt;/source&amp;gt; are all element nodes. Element nodes can contain child nodes, such as other elements, text nodes, or comment nodes.&lt;br /&gt;
&lt;br /&gt;
==== Text Nodes ====&lt;br /&gt;
&lt;br /&gt;
Text nodes represent the textual content within an HTML element. They can contain plain text, including spaces, line breaks, or any other characters. For instance, in the element&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&amp;lt;p&amp;gt;Hello, &amp;lt;strong&amp;gt;world!&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the text node would contain &amp;quot;Hello,&amp;quot; and &amp;quot;world!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== Attribute Nodes ====&lt;br /&gt;
&lt;br /&gt;
These nodes represent the attributes of an HTML element. An element can have multiple attributes like id, class, src, etc. Attribute nodes contain the name and value of the attribute. For example, in the element&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&amp;lt;img src=&amp;quot;image.jpg&amp;quot; alt=&amp;quot;An image&amp;quot; /&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the `src` and `alt` attributes would be represented as attribute nodes.&lt;br /&gt;
&lt;br /&gt;
==== Comment Nodes ====&lt;br /&gt;
&lt;br /&gt;
Comment nodes represent HTML comments within the document. They are used to add explanatory or descriptive notes that are not displayed in the rendered output. Comment nodes start with &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;!--&amp;lt;/source&amp;gt;and end with &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;--&amp;gt;&amp;lt;/source&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&amp;lt;!-- This is a comment --&amp;gt;&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_HTML&amp;diff=2881</id>
		<title>M1 Introduction to HTML</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_HTML&amp;diff=2881"/>
		<updated>2023-06-27T04:44:33Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Built-in Functionality */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== HTML ==&lt;br /&gt;
&lt;br /&gt;
=== HTML? ===&lt;br /&gt;
&lt;br /&gt;
HTML, which stands for HyperText Markup Language, is the standard language used to create webpages. It describes the structure and content of a webpage. HTML uses a system of tags and attributes to define elements on the page. These elements can be things like headings, paragraphs, links, images, lists, tables, forms, and many more. Each of these elements has a specific tag that describes what it is and helps the browser know how to display it.&lt;br /&gt;
&lt;br /&gt;
Here's a very basic example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
  &amp;lt;head&amp;gt;&lt;br /&gt;
    &amp;lt;title&amp;gt;My First Web Page&amp;lt;/title&amp;gt;&lt;br /&gt;
  &amp;lt;/head&amp;gt;&lt;br /&gt;
  &amp;lt;body&amp;gt;&lt;br /&gt;
    &amp;lt;h1&amp;gt;Welcome to My Website!&amp;lt;/h1&amp;gt;&lt;br /&gt;
    &amp;lt;p&amp;gt;This is a paragraph of text.&amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Image will go here'''&lt;br /&gt;
&lt;br /&gt;
In this example:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;!DOCTYPE html&amp;gt;&amp;lt;/source&amp;gt; is the document type declaration. This tells the browser that this document is an HTML document.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;html&amp;gt;&amp;lt;/source&amp;gt; tag is the root of an HTML document.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;head&amp;gt;&amp;lt;/source&amp;gt; tag contains meta-information about the document. This can include the title, character set declarations, CSS style definitions, and more.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/source&amp;gt; tag is the title of the document and is displayed in the browser's title bar or tab.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;body&amp;gt;&amp;lt;/source&amp;gt; tag contains the content of the document, such as text, hyperlinks, images, tables, lists, etc. When you visit a website, the content you see is rendered in the body.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt; tag defines a top-level heading, and the &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/source&amp;gt; tag defines a paragraph.&lt;br /&gt;
&lt;br /&gt;
In essence, HTML gives the webpage its basic structure and content; without it, a webpage can't exist.&lt;br /&gt;
&lt;br /&gt;
=== Tags ===&lt;br /&gt;
&lt;br /&gt;
Tags in HTML are special words or symbols enclosed in angle brackets (&amp;lt; &amp;gt;) that define the structure and formatting of elements within a web page. They act as instructions to the web browser on how to display and interpret the content. Opening tags, such as &amp;lt;tagname&amp;gt;, mark the beginning of an element, while closing tags, like &amp;lt;/tagname&amp;gt;, denote the end. Tags are like containers that hold different types of content, such as text, images, links, or other elements, and they play a crucial role in creating the structure and appearance of a webpage.&lt;br /&gt;
&lt;br /&gt;
Here are some of the most common HTML tags you will encounter. Get to know these well. For more information on how to use a given tag, [https://developer.mozilla.org/en-US/docs/Web/HTML/Element|the MDN docs] are an incredible resource.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:15%&amp;quot; | Tag&lt;br /&gt;
! style=&amp;quot;width:85%&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;html&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines the root element of an HTML document.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;head&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Contains metadata and information about the HTML document. (docs)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Sets the title of the document, displayed in the browser's title bar or tab. (docs)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;body&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents the main content of the HTML document.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt; to &amp;lt;source lang=&amp;quot;html&amp;quot;enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines headings of different levels, from the most important (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt;) to the least (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents a paragraph of text.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;a&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates a hyperlink to another web page, file, or a specific location within the same page.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;img&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Inserts an image into the HTML document.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents an unordered list (a bulleted list).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ol&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents an ordered list (a numbered list).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;li&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines an item in a list (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;/source&amp;gt; or &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ol&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;table&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents tabular data organized into rows and columns.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a row within a table.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;td&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a cell within a table row (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;th&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a header cell within a table row (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;div&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a division or a container for other elements.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;span&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines an inline container for a small section of HTML.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;form&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates an interactive form for user input.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;input&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates an input field for user data entry.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;button&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates a clickable button.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;textarea&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates a multiline text input field.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Built-in Functionality ===&lt;br /&gt;
&lt;br /&gt;
While HTML primarily focuses on structure and content, some HTML tags come with built-in functionality that extends beyond that. These tags incorporate specific behaviors or interactivity into the elements they define. For example, the &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;a&amp;gt;&amp;lt;/source&amp;gt; tag creates hyperlinks, allowing users to navigate to different web pages or sections within the same page. The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;form&amp;gt;&amp;lt;/source&amp;gt; tag enables the creation of interactive forms to gather user input, and the &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;input&amp;gt;&amp;lt;/source&amp;gt; tag provides various types of input fields like text boxes or checkboxes.&lt;br /&gt;
&lt;br /&gt;
To learn about less common tags with fun built-in functionality, see the optional reading, [[M1 HTML Extended|HTML Extended]]. I also encourage you to spend some time exploring [https://developer.mozilla.org/en-US/docs/Web/HTML/Element|the MDN docs].&lt;br /&gt;
&lt;br /&gt;
=== Default Styling ===&lt;br /&gt;
&lt;br /&gt;
When rendering HTML documents, web browsers apply default styles to each HTML element. These default styles determine how the elements are displayed visually, such as their font, color, size, spacing, and positioning. However, it's important to note that default styles may vary slightly between different browsers.&lt;br /&gt;
&lt;br /&gt;
Browsers have their own predefined stylesheets, often referred to as user agent stylesheets, which dictate the initial appearance of HTML elements. This means that even without explicitly applying any styles, elements will still have some visual presentation based on these default styles.&lt;br /&gt;
&lt;br /&gt;
See [M1 Introduction to CSS|Introduction to CSS] for a guide to styling elements.&lt;br /&gt;
&lt;br /&gt;
=== Nodes ===&lt;br /&gt;
&lt;br /&gt;
Where a tag is a syntax used in HTML to define elements, a node is a conceptual representation of an element within the Document Object Model (DOM) hierarchy. In simpler terms, a tag is the markup language used to define an element, whereas a node is an object that represents that element within the structured model of the HTML document.&lt;br /&gt;
&lt;br /&gt;
Nodes form a hierarchical structure known as the Document Object Model (DOM). The DOM represents the HTML document as a tree-like structure, where each node has a relationship with its parent, children, and siblings. The topmost node in the DOM is the document node, representing the entire HTML document.&lt;br /&gt;
&lt;br /&gt;
Here are the main types of nodes commonly encountered in HTML:&lt;br /&gt;
&lt;br /&gt;
==== Element Nodes ====&lt;br /&gt;
&lt;br /&gt;
These nodes represent HTML elements and are the most common type. They correspond to the opening and closing tags of an HTML element. For example, &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;div&amp;gt;...&amp;lt;/div&amp;gt;&amp;lt;/source&amp;gt;, &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;p&amp;gt;...&amp;lt;/p&amp;gt;&amp;lt;/source&amp;gt;, &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;...&amp;lt;/h1&amp;gt;&amp;lt;/source&amp;gt; are all element nodes. Element nodes can contain child nodes, such as other elements, text nodes, or comment nodes.&lt;br /&gt;
&lt;br /&gt;
==== Text Nodes ====&lt;br /&gt;
&lt;br /&gt;
Text nodes represent the textual content within an HTML element. They can contain plain text, including spaces, line breaks, or any other characters. For instance, in the element&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&amp;lt;p&amp;gt;Hello, &amp;lt;strong&amp;gt;world!&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the text node would contain &amp;quot;Hello,&amp;quot; and &amp;quot;world!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== Attribute Nodes ====&lt;br /&gt;
&lt;br /&gt;
These nodes represent the attributes of an HTML element. An element can have multiple attributes like id, class, src, etc. Attribute nodes contain the name and value of the attribute. For example, in the element&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&amp;lt;img src=&amp;quot;image.jpg&amp;quot; alt=&amp;quot;An image&amp;quot; /&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the `src` and `alt` attributes would be represented as attribute nodes.&lt;br /&gt;
&lt;br /&gt;
==== Comment Nodes ====&lt;br /&gt;
&lt;br /&gt;
Comment nodes represent HTML comments within the document. They are used to add explanatory or descriptive notes that are not displayed in the rendered output. Comment nodes start with &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;!--&amp;lt;/source&amp;gt;and end with &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;--&amp;gt;&amp;lt;/source&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&amp;lt;!-- This is a comment --&amp;gt;&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_HTML&amp;diff=2880</id>
		<title>M1 Introduction to HTML</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_HTML&amp;diff=2880"/>
		<updated>2023-06-27T04:41:27Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* HTML */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== HTML ==&lt;br /&gt;
&lt;br /&gt;
=== HTML? ===&lt;br /&gt;
&lt;br /&gt;
HTML, which stands for HyperText Markup Language, is the standard language used to create webpages. It describes the structure and content of a webpage. HTML uses a system of tags and attributes to define elements on the page. These elements can be things like headings, paragraphs, links, images, lists, tables, forms, and many more. Each of these elements has a specific tag that describes what it is and helps the browser know how to display it.&lt;br /&gt;
&lt;br /&gt;
Here's a very basic example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
  &amp;lt;head&amp;gt;&lt;br /&gt;
    &amp;lt;title&amp;gt;My First Web Page&amp;lt;/title&amp;gt;&lt;br /&gt;
  &amp;lt;/head&amp;gt;&lt;br /&gt;
  &amp;lt;body&amp;gt;&lt;br /&gt;
    &amp;lt;h1&amp;gt;Welcome to My Website!&amp;lt;/h1&amp;gt;&lt;br /&gt;
    &amp;lt;p&amp;gt;This is a paragraph of text.&amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Image will go here'''&lt;br /&gt;
&lt;br /&gt;
In this example:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;!DOCTYPE html&amp;gt;&amp;lt;/source&amp;gt; is the document type declaration. This tells the browser that this document is an HTML document.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;html&amp;gt;&amp;lt;/source&amp;gt; tag is the root of an HTML document.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;head&amp;gt;&amp;lt;/source&amp;gt; tag contains meta-information about the document. This can include the title, character set declarations, CSS style definitions, and more.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/source&amp;gt; tag is the title of the document and is displayed in the browser's title bar or tab.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;body&amp;gt;&amp;lt;/source&amp;gt; tag contains the content of the document, such as text, hyperlinks, images, tables, lists, etc. When you visit a website, the content you see is rendered in the body.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt; tag defines a top-level heading, and the &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/source&amp;gt; tag defines a paragraph.&lt;br /&gt;
&lt;br /&gt;
In essence, HTML gives the webpage its basic structure and content; without it, a webpage can't exist.&lt;br /&gt;
&lt;br /&gt;
=== Tags ===&lt;br /&gt;
&lt;br /&gt;
Tags in HTML are special words or symbols enclosed in angle brackets (&amp;lt; &amp;gt;) that define the structure and formatting of elements within a web page. They act as instructions to the web browser on how to display and interpret the content. Opening tags, such as &amp;lt;tagname&amp;gt;, mark the beginning of an element, while closing tags, like &amp;lt;/tagname&amp;gt;, denote the end. Tags are like containers that hold different types of content, such as text, images, links, or other elements, and they play a crucial role in creating the structure and appearance of a webpage.&lt;br /&gt;
&lt;br /&gt;
Here are some of the most common HTML tags you will encounter. Get to know these well. For more information on how to use a given tag, [https://developer.mozilla.org/en-US/docs/Web/HTML/Element|the MDN docs] are an incredible resource.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:15%&amp;quot; | Tag&lt;br /&gt;
! style=&amp;quot;width:85%&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;html&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines the root element of an HTML document.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;head&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Contains metadata and information about the HTML document. (docs)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Sets the title of the document, displayed in the browser's title bar or tab. (docs)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;body&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents the main content of the HTML document.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt; to &amp;lt;source lang=&amp;quot;html&amp;quot;enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines headings of different levels, from the most important (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt;) to the least (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents a paragraph of text.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;a&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates a hyperlink to another web page, file, or a specific location within the same page.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;img&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Inserts an image into the HTML document.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents an unordered list (a bulleted list).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ol&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents an ordered list (a numbered list).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;li&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines an item in a list (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;/source&amp;gt; or &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ol&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;table&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents tabular data organized into rows and columns.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a row within a table.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;td&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a cell within a table row (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;th&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a header cell within a table row (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;div&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a division or a container for other elements.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;span&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines an inline container for a small section of HTML.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;form&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates an interactive form for user input.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;input&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates an input field for user data entry.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;button&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates a clickable button.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;textarea&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates a multiline text input field.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Built-in Functionality ===&lt;br /&gt;
&lt;br /&gt;
While HTML primarily focuses on structure and content, some HTML tags come with built-in functionality that extends beyond that. These tags incorporate specific behaviors or interactivity into the elements they define. For example, the &amp;lt;nowiki&amp;gt;&amp;lt;a&amp;gt;&amp;lt;/nowiki&amp;gt; tag creates hyperlinks, allowing users to navigate to different web pages or sections within the same page. The &amp;lt;nowiki&amp;gt;&amp;lt;form&amp;gt;&amp;lt;/nowiki&amp;gt; tag enables the creation of interactive forms to gather user input, and the &amp;lt;nowiki&amp;gt;&amp;lt;input&amp;gt;&amp;lt;/nowiki&amp;gt; tag provides various types of input fields like text boxes or checkboxes.&lt;br /&gt;
&lt;br /&gt;
To learn about less common tags with fun built-in functionality, see the optional reading, [[HTML Extended|../optional/HTML_extended.md]]. I also encourage you to spend some time exploring [the MDN docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Element).&lt;br /&gt;
&lt;br /&gt;
=== Default Styling ===&lt;br /&gt;
&lt;br /&gt;
When rendering HTML documents, web browsers apply default styles to each HTML element. These default styles determine how the elements are displayed visually, such as their font, color, size, spacing, and positioning. However, it's important to note that default styles may vary slightly between different browsers.&lt;br /&gt;
&lt;br /&gt;
Browsers have their own predefined stylesheets, often referred to as user agent stylesheets, which dictate the initial appearance of HTML elements. This means that even without explicitly applying any styles, elements will still have some visual presentation based on these default styles.&lt;br /&gt;
&lt;br /&gt;
See [M1 Introduction to CSS|Introduction to CSS] for a guide to styling elements.&lt;br /&gt;
&lt;br /&gt;
=== Nodes ===&lt;br /&gt;
&lt;br /&gt;
Where a tag is a syntax used in HTML to define elements, a node is a conceptual representation of an element within the Document Object Model (DOM) hierarchy. In simpler terms, a tag is the markup language used to define an element, whereas a node is an object that represents that element within the structured model of the HTML document.&lt;br /&gt;
&lt;br /&gt;
Nodes form a hierarchical structure known as the Document Object Model (DOM). The DOM represents the HTML document as a tree-like structure, where each node has a relationship with its parent, children, and siblings. The topmost node in the DOM is the document node, representing the entire HTML document.&lt;br /&gt;
&lt;br /&gt;
Here are the main types of nodes commonly encountered in HTML:&lt;br /&gt;
&lt;br /&gt;
==== Element Nodes ====&lt;br /&gt;
&lt;br /&gt;
These nodes represent HTML elements and are the most common type. They correspond to the opening and closing tags of an HTML element. For example, &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;div&amp;gt;...&amp;lt;/div&amp;gt;&amp;lt;/source&amp;gt;, &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;p&amp;gt;...&amp;lt;/p&amp;gt;&amp;lt;/source&amp;gt;, &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;...&amp;lt;/h1&amp;gt;&amp;lt;/source&amp;gt; are all element nodes. Element nodes can contain child nodes, such as other elements, text nodes, or comment nodes.&lt;br /&gt;
&lt;br /&gt;
==== Text Nodes ====&lt;br /&gt;
&lt;br /&gt;
Text nodes represent the textual content within an HTML element. They can contain plain text, including spaces, line breaks, or any other characters. For instance, in the element&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&amp;lt;p&amp;gt;Hello, &amp;lt;strong&amp;gt;world!&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the text node would contain &amp;quot;Hello,&amp;quot; and &amp;quot;world!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
==== Attribute Nodes ====&lt;br /&gt;
&lt;br /&gt;
These nodes represent the attributes of an HTML element. An element can have multiple attributes like id, class, src, etc. Attribute nodes contain the name and value of the attribute. For example, in the element&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&amp;lt;img src=&amp;quot;image.jpg&amp;quot; alt=&amp;quot;An image&amp;quot; /&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the `src` and `alt` attributes would be represented as attribute nodes.&lt;br /&gt;
&lt;br /&gt;
==== Comment Nodes ====&lt;br /&gt;
&lt;br /&gt;
Comment nodes represent HTML comments within the document. They are used to add explanatory or descriptive notes that are not displayed in the rendered output. Comment nodes start with &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;!--&amp;lt;/source&amp;gt;and end with &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;--&amp;gt;&amp;lt;/source&amp;gt;. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&amp;lt;!-- This is a comment --&amp;gt;&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_HTML&amp;diff=2879</id>
		<title>M1 Introduction to HTML</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_HTML&amp;diff=2879"/>
		<updated>2023-06-27T04:31:49Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Tags */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== HTML ==&lt;br /&gt;
&lt;br /&gt;
=== HTML? ===&lt;br /&gt;
&lt;br /&gt;
HTML, which stands for HyperText Markup Language, is the standard language used to create webpages. It describes the structure and content of a webpage. HTML uses a system of tags and attributes to define elements on the page. These elements can be things like headings, paragraphs, links, images, lists, tables, forms, and many more. Each of these elements has a specific tag that describes what it is and helps the browser know how to display it.&lt;br /&gt;
&lt;br /&gt;
Here's a very basic example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
  &amp;lt;head&amp;gt;&lt;br /&gt;
    &amp;lt;title&amp;gt;My First Web Page&amp;lt;/title&amp;gt;&lt;br /&gt;
  &amp;lt;/head&amp;gt;&lt;br /&gt;
  &amp;lt;body&amp;gt;&lt;br /&gt;
    &amp;lt;h1&amp;gt;Welcome to My Website!&amp;lt;/h1&amp;gt;&lt;br /&gt;
    &amp;lt;p&amp;gt;This is a paragraph of text.&amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Image will go here'''&lt;br /&gt;
&lt;br /&gt;
In this example:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;!DOCTYPE html&amp;gt;&amp;lt;/source&amp;gt; is the document type declaration. This tells the browser that this document is an HTML document.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;html&amp;gt;&amp;lt;/source&amp;gt; tag is the root of an HTML document.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;head&amp;gt;&amp;lt;/source&amp;gt; tag contains meta-information about the document. This can include the title, character set declarations, CSS style definitions, and more.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/source&amp;gt; tag is the title of the document and is displayed in the browser's title bar or tab.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;body&amp;gt;&amp;lt;/source&amp;gt; tag contains the content of the document, such as text, hyperlinks, images, tables, lists, etc. When you visit a website, the content you see is rendered in the body.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt; tag defines a top-level heading, and the &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/source&amp;gt; tag defines a paragraph.&lt;br /&gt;
&lt;br /&gt;
In essence, HTML gives the webpage its basic structure and content; without it, a webpage can't exist.&lt;br /&gt;
&lt;br /&gt;
=== Tags ===&lt;br /&gt;
&lt;br /&gt;
Tags in HTML are special words or symbols enclosed in angle brackets (&amp;lt; &amp;gt;) that define the structure and formatting of elements within a web page. They act as instructions to the web browser on how to display and interpret the content. Opening tags, such as &amp;lt;tagname&amp;gt;, mark the beginning of an element, while closing tags, like &amp;lt;/tagname&amp;gt;, denote the end. Tags are like containers that hold different types of content, such as text, images, links, or other elements, and they play a crucial role in creating the structure and appearance of a webpage.&lt;br /&gt;
&lt;br /&gt;
Here are some of the most common HTML tags you will encounter. Get to know these well. For more information on how to use a given tag, [https://developer.mozilla.org/en-US/docs/Web/HTML/Element|the MDN docs] are an incredible resource.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:15%&amp;quot; | Tag&lt;br /&gt;
! style=&amp;quot;width:85%&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;html&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines the root element of an HTML document.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;head&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Contains metadata and information about the HTML document. (docs)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Sets the title of the document, displayed in the browser's title bar or tab. (docs)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;body&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents the main content of the HTML document.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt; to &amp;lt;source lang=&amp;quot;html&amp;quot;enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines headings of different levels, from the most important (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt;) to the least (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents a paragraph of text.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;a&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates a hyperlink to another web page, file, or a specific location within the same page.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;img&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Inserts an image into the HTML document.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents an unordered list (a bulleted list).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ol&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents an ordered list (a numbered list).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;li&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines an item in a list (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;/source&amp;gt; or &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ol&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;table&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents tabular data organized into rows and columns.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a row within a table.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;td&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a cell within a table row (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;th&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a header cell within a table row (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;div&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a division or a container for other elements.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;span&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines an inline container for a small section of HTML.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;form&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates an interactive form for user input.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;input&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates an input field for user data entry.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;button&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates a clickable button.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;textarea&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates a multiline text input field.&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_HTML&amp;diff=2878</id>
		<title>M1 Introduction to HTML</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_HTML&amp;diff=2878"/>
		<updated>2023-06-27T04:26:32Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Tags */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== HTML ==&lt;br /&gt;
&lt;br /&gt;
=== HTML? ===&lt;br /&gt;
&lt;br /&gt;
HTML, which stands for HyperText Markup Language, is the standard language used to create webpages. It describes the structure and content of a webpage. HTML uses a system of tags and attributes to define elements on the page. These elements can be things like headings, paragraphs, links, images, lists, tables, forms, and many more. Each of these elements has a specific tag that describes what it is and helps the browser know how to display it.&lt;br /&gt;
&lt;br /&gt;
Here's a very basic example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
  &amp;lt;head&amp;gt;&lt;br /&gt;
    &amp;lt;title&amp;gt;My First Web Page&amp;lt;/title&amp;gt;&lt;br /&gt;
  &amp;lt;/head&amp;gt;&lt;br /&gt;
  &amp;lt;body&amp;gt;&lt;br /&gt;
    &amp;lt;h1&amp;gt;Welcome to My Website!&amp;lt;/h1&amp;gt;&lt;br /&gt;
    &amp;lt;p&amp;gt;This is a paragraph of text.&amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Image will go here'''&lt;br /&gt;
&lt;br /&gt;
In this example:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;!DOCTYPE html&amp;gt;&amp;lt;/source&amp;gt; is the document type declaration. This tells the browser that this document is an HTML document.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;html&amp;gt;&amp;lt;/source&amp;gt; tag is the root of an HTML document.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;head&amp;gt;&amp;lt;/source&amp;gt; tag contains meta-information about the document. This can include the title, character set declarations, CSS style definitions, and more.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/source&amp;gt; tag is the title of the document and is displayed in the browser's title bar or tab.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;body&amp;gt;&amp;lt;/source&amp;gt; tag contains the content of the document, such as text, hyperlinks, images, tables, lists, etc. When you visit a website, the content you see is rendered in the body.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt; tag defines a top-level heading, and the &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/source&amp;gt; tag defines a paragraph.&lt;br /&gt;
&lt;br /&gt;
In essence, HTML gives the webpage its basic structure and content; without it, a webpage can't exist.&lt;br /&gt;
&lt;br /&gt;
=== Tags ===&lt;br /&gt;
&lt;br /&gt;
Tags in HTML are special words or symbols enclosed in angle brackets (&amp;lt; &amp;gt;) that define the structure and formatting of elements within a web page. They act as instructions to the web browser on how to display and interpret the content. Opening tags, such as &amp;lt;tagname&amp;gt;, mark the beginning of an element, while closing tags, like &amp;lt;/tagname&amp;gt;, denote the end. Tags are like containers that hold different types of content, such as text, images, links, or other elements, and they play a crucial role in creating the structure and appearance of a webpage.&lt;br /&gt;
&lt;br /&gt;
Here are some of the most common HTML tags you will encounter. Get to know these well. For more information on how to use a given tag, [[https://developer.mozilla.org/en-US/docs/Web/HTML/Element|the MDN docs]] are an incredible resource.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:15%&amp;quot; | Tag&lt;br /&gt;
! style=&amp;quot;width:85%&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;html&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines the root element of an HTML document.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;head&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Contains metadata and information about the HTML document. (docs)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Sets the title of the document, displayed in the browser's title bar or tab. (docs)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;body&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents the main content of the HTML document.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt; to &amp;lt;source lang=&amp;quot;html&amp;quot;enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines headings of different levels, from the most important (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt;) to the least (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents a paragraph of text.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;a&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates a hyperlink to another web page, file, or a specific location within the same page.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;img&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Inserts an image into the HTML document.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents an unordered list (a bulleted list).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ol&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents an ordered list (a numbered list).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;li&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines an item in a list (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;/source&amp;gt; or &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;ol&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;table&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents tabular data organized into rows and columns.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a row within a table.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;td&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a cell within a table row (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;th&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a header cell within a table row (&amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;div&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a division or a container for other elements.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;span&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines an inline container for a small section of HTML.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;form&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates an interactive form for user input.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;input&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates an input field for user data entry.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;button&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates a clickable button.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;textarea&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates a multiline text input field.&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_HTML&amp;diff=2877</id>
		<title>M1 Introduction to HTML</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_HTML&amp;diff=2877"/>
		<updated>2023-06-27T04:21:15Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Tags */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== HTML ==&lt;br /&gt;
&lt;br /&gt;
=== HTML? ===&lt;br /&gt;
&lt;br /&gt;
HTML, which stands for HyperText Markup Language, is the standard language used to create webpages. It describes the structure and content of a webpage. HTML uses a system of tags and attributes to define elements on the page. These elements can be things like headings, paragraphs, links, images, lists, tables, forms, and many more. Each of these elements has a specific tag that describes what it is and helps the browser know how to display it.&lt;br /&gt;
&lt;br /&gt;
Here's a very basic example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
  &amp;lt;head&amp;gt;&lt;br /&gt;
    &amp;lt;title&amp;gt;My First Web Page&amp;lt;/title&amp;gt;&lt;br /&gt;
  &amp;lt;/head&amp;gt;&lt;br /&gt;
  &amp;lt;body&amp;gt;&lt;br /&gt;
    &amp;lt;h1&amp;gt;Welcome to My Website!&amp;lt;/h1&amp;gt;&lt;br /&gt;
    &amp;lt;p&amp;gt;This is a paragraph of text.&amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Image will go here'''&lt;br /&gt;
&lt;br /&gt;
In this example:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;!DOCTYPE html&amp;gt;&amp;lt;/source&amp;gt; is the document type declaration. This tells the browser that this document is an HTML document.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;html&amp;gt;&amp;lt;/source&amp;gt; tag is the root of an HTML document.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;head&amp;gt;&amp;lt;/source&amp;gt; tag contains meta-information about the document. This can include the title, character set declarations, CSS style definitions, and more.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/source&amp;gt; tag is the title of the document and is displayed in the browser's title bar or tab.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;body&amp;gt;&amp;lt;/source&amp;gt; tag contains the content of the document, such as text, hyperlinks, images, tables, lists, etc. When you visit a website, the content you see is rendered in the body.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt; tag defines a top-level heading, and the &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/source&amp;gt; tag defines a paragraph.&lt;br /&gt;
&lt;br /&gt;
In essence, HTML gives the webpage its basic structure and content; without it, a webpage can't exist.&lt;br /&gt;
&lt;br /&gt;
=== Tags ===&lt;br /&gt;
&lt;br /&gt;
Tags in HTML are special words or symbols enclosed in angle brackets (&amp;lt; &amp;gt;) that define the structure and formatting of elements within a web page. They act as instructions to the web browser on how to display and interpret the content. Opening tags, such as &amp;lt;tagname&amp;gt;, mark the beginning of an element, while closing tags, like &amp;lt;/tagname&amp;gt;, denote the end. Tags are like containers that hold different types of content, such as text, images, links, or other elements, and they play a crucial role in creating the structure and appearance of a webpage.&lt;br /&gt;
&lt;br /&gt;
Here are some of the most common HTML tags you will encounter. Get to know these well. For more information on how to use a given tag, [[https://developer.mozilla.org/en-US/docs/Web/HTML/Element|the MDN docs]] are an incredible resource.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;width:15%&amp;quot; | Tag&lt;br /&gt;
! style=&amp;quot;width:85%&amp;quot; | Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;html&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines the root element of an HTML document.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;head&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Contains metadata and information about the HTML document. (docs)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Sets the title of the document, displayed in the browser's title bar or tab. (docs)&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;body&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents the main content of the HTML document.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt; to &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines headings of different levels, from the most important (&amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt;) to the least (&amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;h6&amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents a paragraph of text.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;a&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates a hyperlink to another web page, file, or a specific location within the same page.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;img&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Inserts an image into the HTML document.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents an unordered list (a bulleted list).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;ol&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents an ordered list (a numbered list).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;li&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines an item in a list (&amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;amp;lt;ul&amp;amp;gt;&amp;lt;/source&amp;gt; or &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;amp;lt;ol&amp;amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;table&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Represents tabular data organized into rows and columns.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a row within a table.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;td&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a cell within a table row (&amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;amp;lt;tr&amp;amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;th&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a header cell within a table row (&amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;amp;lt;tr&amp;amp;gt;&amp;lt;/source&amp;gt;).&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;div&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines a division or a container for other elements.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;span&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Defines an inline container for a small section of HTML.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;form&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates an interactive form for user input.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;input&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates an input field for user data entry.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;button&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates a clickable button.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;source lang=&amp;quot;html&amp;quot; enclosed=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;textarea&amp;gt;&amp;lt;/source&amp;gt;&lt;br /&gt;
| Creates a multiline text input field.&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_HTML&amp;diff=2876</id>
		<title>M1 Introduction to HTML</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_HTML&amp;diff=2876"/>
		<updated>2023-06-27T04:05:12Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* HTML? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== HTML ==&lt;br /&gt;
&lt;br /&gt;
=== HTML? ===&lt;br /&gt;
&lt;br /&gt;
HTML, which stands for HyperText Markup Language, is the standard language used to create webpages. It describes the structure and content of a webpage. HTML uses a system of tags and attributes to define elements on the page. These elements can be things like headings, paragraphs, links, images, lists, tables, forms, and many more. Each of these elements has a specific tag that describes what it is and helps the browser know how to display it.&lt;br /&gt;
&lt;br /&gt;
Here's a very basic example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
  &amp;lt;head&amp;gt;&lt;br /&gt;
    &amp;lt;title&amp;gt;My First Web Page&amp;lt;/title&amp;gt;&lt;br /&gt;
  &amp;lt;/head&amp;gt;&lt;br /&gt;
  &amp;lt;body&amp;gt;&lt;br /&gt;
    &amp;lt;h1&amp;gt;Welcome to My Website!&amp;lt;/h1&amp;gt;&lt;br /&gt;
    &amp;lt;p&amp;gt;This is a paragraph of text.&amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Image will go here'''&lt;br /&gt;
&lt;br /&gt;
In this example:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;!DOCTYPE html&amp;gt;&amp;lt;/source&amp;gt; is the document type declaration. This tells the browser that this document is an HTML document.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;html&amp;gt;&amp;lt;/source&amp;gt; tag is the root of an HTML document.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;head&amp;gt;&amp;lt;/source&amp;gt; tag contains meta-information about the document. This can include the title, character set declarations, CSS style definitions, and more.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/source&amp;gt; tag is the title of the document and is displayed in the browser's title bar or tab.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;body&amp;gt;&amp;lt;/source&amp;gt; tag contains the content of the document, such as text, hyperlinks, images, tables, lists, etc. When you visit a website, the content you see is rendered in the body.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt; tag defines a top-level heading, and the &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/source&amp;gt; tag defines a paragraph.&lt;br /&gt;
&lt;br /&gt;
In essence, HTML gives the webpage its basic structure and content; without it, a webpage can't exist.&lt;br /&gt;
&lt;br /&gt;
=== Tags ===&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_HTML&amp;diff=2875</id>
		<title>M1 Introduction to HTML</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Introduction_to_HTML&amp;diff=2875"/>
		<updated>2023-06-27T03:46:45Z</updated>

		<summary type="html">&lt;p&gt;Zach: Created page with &amp;quot;== HTML ==  === HTML? ===  HTML, which stands for HyperText Markup Language, is the standard language used to create webpages. It describes the structure and content of a webp...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== HTML ==&lt;br /&gt;
&lt;br /&gt;
=== HTML? ===&lt;br /&gt;
&lt;br /&gt;
HTML, which stands for HyperText Markup Language, is the standard language used to create webpages. It describes the structure and content of a webpage. HTML uses a system of tags and attributes to define elements on the page. These elements can be things like headings, paragraphs, links, images, lists, tables, forms, and many more. Each of these elements has a specific tag that describes what it is and helps the browser know how to display it.&lt;br /&gt;
&lt;br /&gt;
Here's a very basic example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
  &amp;lt;head&amp;gt;&lt;br /&gt;
    &amp;lt;title&amp;gt;My First Web Page&amp;lt;/title&amp;gt;&lt;br /&gt;
  &amp;lt;/head&amp;gt;&lt;br /&gt;
  &amp;lt;body&amp;gt;&lt;br /&gt;
    &amp;lt;h1&amp;gt;Welcome to My Website!&amp;lt;/h1&amp;gt;&lt;br /&gt;
    &amp;lt;p&amp;gt;This is a paragraph of text.&amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
IMAGE GOES HERE&lt;br /&gt;
&lt;br /&gt;
In this example:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;!DOCTYPE html&amp;gt;&amp;lt;/source&amp;gt; is the document type declaration. This tells the browser that this document is an HTML document.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;html&amp;gt;&amp;lt;/source&amp;gt; tag is the root of an HTML document.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;head&amp;gt;&amp;lt;/source&amp;gt; tag contains meta-information about the document. This can include the title, character set declarations, CSS style definitions, and more.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;title&amp;gt;&amp;lt;/source&amp;gt; tag is the title of the document and is displayed in the browser's title bar or tab.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;body&amp;gt;&amp;lt;/source&amp;gt; tag contains the content of the document, such as text, hyperlinks, images, tables, lists, etc. When you visit a website, the content you see is rendered in the body.&lt;br /&gt;
* The &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;h1&amp;gt;&amp;lt;/source&amp;gt; tag defines a top-level heading, and the &amp;lt;source lang=&amp;quot;html&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;&amp;lt;p&amp;gt;&amp;lt;/source&amp;gt; tag defines a paragraph.&lt;br /&gt;
&lt;br /&gt;
In essence, HTML gives the webpage its basic structure and content; without it, a webpage can't exist.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Tags ===&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Reading&amp;diff=2874</id>
		<title>M1 Reading</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=M1_Reading&amp;diff=2874"/>
		<updated>2023-06-27T03:27:00Z</updated>

		<summary type="html">&lt;p&gt;Zach: Created page with &amp;quot;== Module 1 | Reading ==  '''Students should read each page listed under the &amp;quot;Required&amp;quot; heading. These texts will be critical for completing this module's assignment(s).'''...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Module 1 | Reading ==&lt;br /&gt;
&lt;br /&gt;
'''Students should read each page listed under the &amp;quot;Required&amp;quot; heading. These texts will be critical for completing this module's assignment(s).''' &lt;br /&gt;
&lt;br /&gt;
Texts listed as &amp;quot;Supplemental&amp;quot; are highly recommended.&lt;br /&gt;
&lt;br /&gt;
* Required&lt;br /&gt;
** [[M1 Introduction to HTML|Introduction to HTML]]&lt;br /&gt;
** [[M1 Introduction to CSS|Introduction to CSS]]&lt;br /&gt;
** [[M1 Introduction to Git|Introduction to Git]]&lt;br /&gt;
* Supplemental&lt;br /&gt;
** [[M1 Markdown|Markdown]]&lt;br /&gt;
** [[M1 Accessibility|Accessibility]]&lt;br /&gt;
** [[M1 HTML Extended|HTML Extended]]&lt;br /&gt;
** [[M1 CSS Extended|CSS Extended]]&lt;br /&gt;
** [[M1 Git Extended|Git Extended]]&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Rewrite_2023&amp;diff=2873</id>
		<title>Rewrite 2023</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Rewrite_2023&amp;diff=2873"/>
		<updated>2023-06-27T03:23:10Z</updated>

		<summary type="html">&lt;p&gt;Zach: Created page with &amp;quot;== 2023 Wiki reorg == I am working on a rewrite/reorg of the current wiki. In its current state, the wiki has an incredible amount of information, but I've heard from many stu...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== 2023 Wiki reorg ==&lt;br /&gt;
I am working on a rewrite/reorg of the current wiki. In its current state, the wiki has an incredible amount of information, but I've heard from many students that it is difficult to parse and sometimes confusing as to which data is relevant. This effort serves to address some of these issues.&lt;br /&gt;
&lt;br /&gt;
In its current state, students often find it difficult to separate the assignment-critical info from supplementary content. To address this, the rewrite seperates structures each assignment like this:&lt;br /&gt;
&lt;br /&gt;
* Purpose (of module)&lt;br /&gt;
* Assignemnt&lt;br /&gt;
** Individual&lt;br /&gt;
** Group&lt;br /&gt;
&lt;br /&gt;
* Reading&lt;br /&gt;
** Required&lt;br /&gt;
** Optional&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Directory ===&lt;br /&gt;
* [[M1 Index|M1]]&lt;br /&gt;
** [[M1 Purpose|Purpose]]&lt;br /&gt;
** [[M1 Individual|Individual Assignment]]&lt;br /&gt;
** [[M1 Reading|Reading]]&lt;br /&gt;
*** Required&lt;br /&gt;
**** [[M1 Introduction to HTML|Introduction to HTML]]&lt;br /&gt;
**** [[M1 Introduction to CSS|Introduction to CSS]]&lt;br /&gt;
**** [[M1 Introduction to Git|Introduction to Git]]&lt;br /&gt;
*** Supplemental&lt;br /&gt;
**** [[M1 Markdown|Markdown]]&lt;br /&gt;
**** [[M1 Accessibility|Accessibility]]&lt;br /&gt;
**** [[M1 HTML Extended|HTML Extended]]&lt;br /&gt;
**** [[M1 CSS Extended|CSS Extended]]&lt;br /&gt;
**** [[M1 Git Extended|Git Extended]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt; ''More to be added soon. The other modules will follow the same basic structure.''&amp;lt;/blockquote&amp;gt;&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=CSE_330_Online_Textbook_-_Table_of_Contents&amp;diff=2865</id>
		<title>CSE 330 Online Textbook - Table of Contents</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=CSE_330_Online_Textbook_-_Table_of_Contents&amp;diff=2865"/>
		<updated>2023-02-07T19:20:31Z</updated>

		<summary type="html">&lt;p&gt;Zach: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&amp;lt;div style=&amp;quot;text-align:center;&amp;quot;&amp;gt;[[File:CSE330Banner.png]]&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
__NOTOC__ &lt;br /&gt;
&amp;lt;div style=&amp;quot;column-width: 300px; -moz-column-width: 300px; -webkit-column-width: 300px;&amp;quot;&amp;gt;&lt;br /&gt;
{{FrontPageModule&lt;br /&gt;
|num=1&lt;br /&gt;
|subject=HTML and CSS Fundamentals&lt;br /&gt;
|links=&lt;br /&gt;
* [[HTML and CSS]]&lt;br /&gt;
* [[HTML Forms]]&lt;br /&gt;
* [[Git]]&lt;br /&gt;
* [[FAQ - Mod 1]]&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FrontPageModule&lt;br /&gt;
|num=2&lt;br /&gt;
|subject=Linux, Apache, and PHP&lt;br /&gt;
|links=&lt;br /&gt;
* [[Linux]]&lt;br /&gt;
* [[Bash]]&lt;br /&gt;
* [[Amazon Web Services]]&lt;br /&gt;
* [[SSH]]&lt;br /&gt;
* [[Apache]]&lt;br /&gt;
* [[PHP]]&lt;br /&gt;
* [[Workflow]]&lt;br /&gt;
* [[VS Code]]&lt;br /&gt;
* [[Web Application Security, Part 1]]&lt;br /&gt;
* [[FAQ - Mod 2]]&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FrontPageModule&lt;br /&gt;
|num=3&lt;br /&gt;
|subject=SQL Databases&lt;br /&gt;
|links=&lt;br /&gt;
* [[Introduction to MySQL]] (installation)&lt;br /&gt;
* [[MySQL Schema and State]] (queries)&lt;br /&gt;
* [[PHP and MySQL]] (using MySQL from PHP)&lt;br /&gt;
* [[Web Application Security, Part 2]]&lt;br /&gt;
* [[FAQ - Mod 3]]&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FrontPageModule&lt;br /&gt;
|num=4&lt;br /&gt;
|subject=Scripting for Rapid Prototyping&lt;br /&gt;
|links=&lt;br /&gt;
* [[Python]]&lt;br /&gt;
* [[Regular Expressions]]&lt;br /&gt;
* [[FAQ - Mod 4]]&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FrontPageModule&lt;br /&gt;
|num=5&lt;br /&gt;
|subject=JavaScript and APIs&lt;br /&gt;
|links=&lt;br /&gt;
* [[JavaScript]]&lt;br /&gt;
* [[AJAX and JSON]]&lt;br /&gt;
* [[Web Application Security, Part 3]]&lt;br /&gt;
* [[FAQ - Mod 5]]&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{FrontPageModule&lt;br /&gt;
|num=6&lt;br /&gt;
|subject=Real-Time Web Applications&lt;br /&gt;
|links=&lt;br /&gt;
* [[Node.JS]]&lt;br /&gt;
* [[Socket.IO]]&lt;br /&gt;
* [[FAQ - Mod 6]]&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{FrontPageModule&lt;br /&gt;
|num=7&lt;br /&gt;
|subject=Creative Project&lt;br /&gt;
|links=&lt;br /&gt;
* [[Choosing a Platform]]&lt;br /&gt;
* [[Web Frameworks]]&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
&lt;br /&gt;
Use this wiki as a starting place for your projects in CSE 330.  However, web development is a large field, so it is impossible for us to document everything you might need to know.  Here are some other places you should look when you need to find something:&lt;br /&gt;
&lt;br /&gt;
* [https://developer.mozilla.org/en-US/ The Mozilla Development Network (MDN)], a community-driven source containing documentation and tutorials for Web technologies&lt;br /&gt;
* [http://reference.sitepoint.com/html SitePoint], which has a reference page as well as quality articles and tutorials&lt;br /&gt;
&lt;br /&gt;
If you can't find what you need in any of these places, try using your favorite search engine.  '''Be wary of sites that come up on search engines.'''  Many HTML reference sites document bad practices and dated techniques.  If you're unsure whether a reference site you find is legitimate, ask a TA.&lt;br /&gt;
&lt;br /&gt;
== Want to Learn More? ==&lt;br /&gt;
&lt;br /&gt;
The limited amount of time in CSE 330 means that we can cover only a subset of the wide range of possible topics in the field of rapid prototyping and web development.  Indeed, the exact topics covered in CSE 330 change from year to year.&lt;br /&gt;
&lt;br /&gt;
Feel free to browse some of the topics that have previously been covered in CSE 330: [[:Category:Former Content|CSE 330 Former Content]]&lt;br /&gt;
&lt;br /&gt;
You should also consider following blogs like [http://www.sitepoint.com/ SitePoint] to keep up-to-date on the latest developments in the field of web development.&lt;br /&gt;
&lt;br /&gt;
== Content License ==&lt;br /&gt;
&lt;br /&gt;
The content of this wiki is copyright (c) 2013, Washington University in St. Louis, Department of Computer Science.  All rights reserved.&lt;br /&gt;
&lt;br /&gt;
=== Modified BSD License ===&lt;br /&gt;
&lt;br /&gt;
Redistribution and use in source and binary forms, with or without modification, by a Third Party who has not completed and is not in the process of completing CSE 330, of the code examples or concepts on this wiki, are permitted, provided that the following conditions are met:&lt;br /&gt;
&lt;br /&gt;
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.&lt;br /&gt;
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.&lt;br /&gt;
* Neither the name of the Washington University School of Engineering and Applied Science nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.&lt;br /&gt;
&lt;br /&gt;
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS TO ALL PARTIES &amp;quot;AS IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
&lt;br /&gt;
=== What it Means ===&lt;br /&gt;
&lt;br /&gt;
If you are a student in CSE 330, you may use the code from this wiki freely in your projects without the need for attribution.  If you are not a student in CSE 330, you may use the code from this wiki freely in your projects with attribution.  Either way, the code examples are provided &amp;quot;as is&amp;quot;, without any warranty, and Washington University holds no liability for problems arising from the use of the content in this wiki.&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=PHP&amp;diff=2864</id>
		<title>PHP</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=PHP&amp;diff=2864"/>
		<updated>2023-02-07T19:18:04Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Sessions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;PHP is an open-source language used widely for writing server-side code for web servers.  PHP is a good starting point for web developers, as it is straightforward to learn and yet powerful at the same time.  Indeed, some of the internet's most popular web sites (including Facebook and Wikipedia) are written using PHP as their language of choice!  This article introduces the syntax of PHP and how to make a basic PHP web application.&lt;br /&gt;
&lt;br /&gt;
{{XKCD&lt;br /&gt;
|name=mac_pc&lt;br /&gt;
|id=934&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== What is PHP? ==&lt;br /&gt;
&lt;br /&gt;
PHP is a server-side scripting language widely used in web development.  PHP is what turns your web site from a static fileserver into a dynamic web application.&lt;br /&gt;
&lt;br /&gt;
By default, Apache only knows how to serve static HTML pages to the client.  You can write as many HTML pages as you want, which is fine for basic web sites.  But if you want to have users post to a forum, or process credit card transactions, or make your own online calendar, a server-side language like PHP is what you need.&lt;br /&gt;
&lt;br /&gt;
=== Document Generation Language ===&lt;br /&gt;
&lt;br /&gt;
If PHP's original core purpose had to be described in three words, it would be this: '''document generation language'''.  Unlike languages including Java, Ruby, Python, and Perl, which consist of classes in a strict program layout, PHP code is most often embedded inside a template document.  When the PHP interpreter runs, it &amp;quot;fills in the gaps&amp;quot; and generates a finished product document.&lt;br /&gt;
&lt;br /&gt;
This isn't to say that PHP can ''only'' be a document generating language, because this is certainly not true.  However, for the purposes of Module 2, it is safe to think of it this way when you are learning the concepts behind a web server.&lt;br /&gt;
&lt;br /&gt;
==== MIME Types ====&lt;br /&gt;
&lt;br /&gt;
By default, PHP generates HTML documents.  (Recall that an HTML document is simply a block of text consisting of markup conforming to the HTML standard.)&lt;br /&gt;
&lt;br /&gt;
However, PHP does not need to generate HTML documents.  It can also generate images, PDFs, or any other type of document.  Each of these document types has its own unique markup language.  The markup language used by a certain document is defined by its ''MIME Type''.&lt;br /&gt;
&lt;br /&gt;
The HTML MIME Type is '''text/html'''.  Other MIME Types include '''image/jpeg''', '''image/png''', and '''application/xml'''.&lt;br /&gt;
&lt;br /&gt;
To change the MIME Type of the document generated by PHP, use the statement:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
header(&amp;quot;Content-Type: image/jpeg&amp;quot;);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since PHP generates HTML documents by default, you can think of there being an implicit &amp;lt;code&amp;gt;header(&amp;quot;Content-Type: text/html&amp;quot;);&amp;lt;/code&amp;gt; at the top of every PHP script.&lt;br /&gt;
&lt;br /&gt;
=== PHP and Apache ===&lt;br /&gt;
&lt;br /&gt;
When you request a PHP file over Apache, the file is ''not'' sent verbatim.  Instead, it is first sent through the PHP interpreter.  Here is an oversimplified schematic of the process:&lt;br /&gt;
&lt;br /&gt;
[[File:PHP-Apache_Flowchart.png]]&lt;br /&gt;
&lt;br /&gt;
In summary, here are some points to keep in mind.&lt;br /&gt;
&lt;br /&gt;
# A PHP file on your server is not an HTML document.  It is a PHP script.&lt;br /&gt;
# PHP generates documents.  By default, it generates HTML documents.&lt;br /&gt;
# PHP can generate other document types by changing the MIME Type in the Content-Type HTTP Header.&lt;br /&gt;
# Apache runs the PHP interpreter on your PHP script before transmitting it to the browser.  The content that is generated after the PHP interpreter runs is expected to match the MIME type: by default, an HTML document.&lt;br /&gt;
# The W3C Validator checks for valid markup in an HTML document.  Everywhere that PHP generates an HTML document, that HTML document should be valid.&lt;br /&gt;
&lt;br /&gt;
== Installing PHP ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
To install PHP 7.2, run the following command to install php7.2 from the Amazon Linux Extras repository. &lt;br /&gt;
  sudo amazon-linux-extras install -y php7.2&lt;br /&gt;
  sudo service php-fpm start&lt;br /&gt;
&lt;br /&gt;
Once you install the required packages, [[Web Server Configuration#Restarting Apache and Testing|restart Apache]] for the changes to take effect.&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== PHP Configurations ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
The PHP configuration file is called ''php.ini''.  In RHEL, it is located at ''/etc/php.ini''.&lt;br /&gt;
&lt;br /&gt;
The configuration file is largely self-documenting as to what the different options mean.  There is one value in particular that we want to change for the purposes of CSE330.  Open php.ini in your favorite text editor, find the '''display_errors''' option, and set it to '''On''':&lt;br /&gt;
&lt;br /&gt;
 display_errors = On&lt;br /&gt;
&lt;br /&gt;
You will need to restart Apache for any php.ini changes to take effect.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' You can turn errors on or off for a certain PHP script by using the '''error_reporting()''' and/or '''ini_set()''' functions.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' If you tell PHP to log its errors, they will be stored in the Apache error log file, at ''/var/log/php-fpm/www-error.log''.&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Your First PHP Script ==&lt;br /&gt;
&lt;br /&gt;
By default, all files that have the *.php extension will be interpreted as containing PHP code.  &lt;br /&gt;
All files with PHP need to be saved as '.php'; not '.html'.&lt;br /&gt;
Here is the most basic PHP script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
phpinfo();&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Save that code into a file named phpinfo.php, and save it in your web server directory (/var/www/html/).  Load it up in your browser like this: ''http://ec2-blah-blah.compute-1.amazonaws.com/phpinfo.php''&lt;br /&gt;
&lt;br /&gt;
If you see something like this, your PHP installation is working!&lt;br /&gt;
&lt;br /&gt;
[[Image:Php_info.png]]&lt;br /&gt;
&lt;br /&gt;
Look at the source code of that page.  Notice that even though there were only three lines of code in our PHP file, PHP filled it up with hundreds of lines of HTML!&lt;br /&gt;
&lt;br /&gt;
Your own PHP scripts will probably look something more like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
	&amp;lt;title&amp;gt;My First PHP Script&amp;lt;/title&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
echo &amp;quot;\t&amp;lt;p&amp;gt;Hello World!&amp;lt;/p&amp;gt;\n&amp;quot;;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code will send the following HTML to the browser:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
	&amp;lt;title&amp;gt;My First PHP Script&amp;lt;/title&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;Hello World!&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here's the take-home message of this section.  To run PHP code, enclose it in &amp;lt;code&amp;gt;&amp;lt;?php  ?&amp;gt;&amp;lt;/code&amp;gt; tags; HTML code can be used in a PHP file (although not inside the PHP code block!); and just a few lines of code can generate an arbitrary amount of HTML.&lt;br /&gt;
&lt;br /&gt;
== PHP Language Components ==&lt;br /&gt;
&lt;br /&gt;
PHP is a programming language much like others you have learned: it has variables, arrays, functions, objects etc.  However, the syntax for PHP and the way PHP handles variables may be new to you.  This section gives an overview of PHP the language.&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
All variables start with the currency '''$''' symbol.  The '''$''' is necessary for both setting and accessing.&lt;br /&gt;
&lt;br /&gt;
PHP is a weak-typed language; that is, you can set any type of value to a variable (string, array, number, etc), and PHP will accept it, even if that variable previously contained a different data type.  In some ways this is convenient, but in others it can lead to hard-to-detect bugs, so be careful.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$i = 5;  # Set the integer 5 to the variable $i&lt;br /&gt;
$msg = &amp;quot;Hello World&amp;quot;;  # Set the string Hello World to the variable $msg&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice that all lines in PHP necessarily end with a semicolon.  If you forget a semicolon, the PHP will fail to parse!&lt;br /&gt;
&lt;br /&gt;
=== Strings ===&lt;br /&gt;
&lt;br /&gt;
Strings in PHP can be either single-quoted or double-quoted.  Single-quoted strings are always taken literally; double-quoted strings allow for additional elements.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$a = &amp;quot;Apple&amp;quot;;&lt;br /&gt;
$b = &amp;quot;Banana&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
$fruits_double = &amp;quot;$a\n$b&amp;quot;;   # $fruits_double now contains the string Apple (line break) Banana&lt;br /&gt;
$fruits_single = '$a\n$b';   # $fruits_single now contains the string $a\n$b&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to use special characters in a double-quoted strings, escape them using the backslash operator:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$a = &amp;quot;Apple&amp;quot;;&lt;br /&gt;
$b = &amp;quot;Banana&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
$fruits = &amp;quot;\$a\\n$b&amp;quot;;   # $fruits now contains the string $a\nBanana&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can concatenate multiple strings together using the concatenation operator, which in php is a period:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$c = &amp;quot;Cherry&amp;quot;;&lt;br /&gt;
$g = &amp;quot;Grapefruit&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
$fruits = $c.&amp;quot;\n&amp;quot;.$g;   # $fruits contains the string Cherry (line break) Grapefruit&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Arrays ===&lt;br /&gt;
&lt;br /&gt;
Declaring arrays is very simple in PHP.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$fruits = array(&amp;quot;Apple&amp;quot;, &amp;quot;Banana&amp;quot;, &amp;quot;Cherry&amp;quot;, &amp;quot;Grapefruit&amp;quot;);   # $arr now contains an array with 4 items&lt;br /&gt;
&lt;br /&gt;
echo $fruits[1];   # displays Banana&lt;br /&gt;
&lt;br /&gt;
echo count($fruits);   # displays 4&lt;br /&gt;
&lt;br /&gt;
array_shift($fruits);   # remove the first element of the array&lt;br /&gt;
&lt;br /&gt;
echo $fruits[1];   # displays Cherry&lt;br /&gt;
&lt;br /&gt;
echo count($fruits);   # displays 3&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: '''echo''' outputs a string to the browser.  We will see more ways to output data [[#Outputting Data|later in this guide]].&lt;br /&gt;
&lt;br /&gt;
PHP also supports ''associative arrays''.  Associative arrays are arrays whose keys are strings rather than numbers; in some languages, they are called Dictionaries.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$fruits[&amp;quot;a&amp;quot;] = &amp;quot;Apple&amp;quot;;&lt;br /&gt;
$fruits[&amp;quot;b&amp;quot;] = &amp;quot;Banana&amp;quot;;&lt;br /&gt;
$fruits[&amp;quot;c&amp;quot;] = &amp;quot;Cherry&amp;quot;;&lt;br /&gt;
$fruits[&amp;quot;g&amp;quot;] = &amp;quot;Grapefruit&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
echo $fruits[&amp;quot;c&amp;quot;];   # displays Cherry&lt;br /&gt;
&lt;br /&gt;
$keys = array_keys($fruits);   # get an array containing indexed values of the fruits' keys&lt;br /&gt;
&lt;br /&gt;
echo $keys[3];   # displays g&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Conditional Statements ===&lt;br /&gt;
&lt;br /&gt;
Conditional statements work similarly to how they do in other languages.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$grade = 85;&lt;br /&gt;
&lt;br /&gt;
if ($grade &amp;lt; 60) {&lt;br /&gt;
	echo &amp;quot;F&amp;quot;;&lt;br /&gt;
} elseif ($grade &amp;lt; 70) {&lt;br /&gt;
	echo &amp;quot;D&amp;quot;;&lt;br /&gt;
} elseif ($grade &amp;lt; 80) {&lt;br /&gt;
	echo &amp;quot;C&amp;quot;;&lt;br /&gt;
} elseif ($grade &amp;lt; 90) {&lt;br /&gt;
	echo &amp;quot;B&amp;quot;;&lt;br /&gt;
} else {&lt;br /&gt;
	echo &amp;quot;A&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PHP also supports switch statements, which are convenient for simplifying long if/elseif/else blocks:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$food = &amp;quot;Apple&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
switch ($food) {&lt;br /&gt;
&lt;br /&gt;
case &amp;quot;Apple&amp;quot;:&lt;br /&gt;
case &amp;quot;Banana&amp;quot;:&lt;br /&gt;
case &amp;quot;Cherry&amp;quot;:&lt;br /&gt;
case &amp;quot;Grapefruit&amp;quot;:&lt;br /&gt;
	echo &amp;quot;You must like fruit!&amp;quot;;&lt;br /&gt;
	break;&lt;br /&gt;
case &amp;quot;Broccoli&amp;quot;:&lt;br /&gt;
case &amp;quot;Spinach&amp;quot;:&lt;br /&gt;
	echo &amp;quot;You must like vegetables!&amp;quot;;&lt;br /&gt;
	break;&lt;br /&gt;
default:&lt;br /&gt;
	echo &amp;quot;You don't like fruits or vegetables!&amp;quot;;&lt;br /&gt;
	break;&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Loops ===&lt;br /&gt;
&lt;br /&gt;
PHP supports several different kinds of loops, including while, for, and foreach:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
$mystring = &amp;quot;&amp;quot;;&lt;br /&gt;
$i = 0;&lt;br /&gt;
while ($i &amp;lt; 5) {&lt;br /&gt;
	$mystring .= &amp;quot;Blah&amp;quot;;&lt;br /&gt;
	$i++;&lt;br /&gt;
}&lt;br /&gt;
echo $mystring;   # displays BlahBlahBlahBlahBlah&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
$myarray = array(&amp;quot;Apple&amp;quot;, &amp;quot;Banana&amp;quot;, &amp;quot;Cherry&amp;quot;, &amp;quot;Grapefruit&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
# The following two loops are functionally equivalent.&lt;br /&gt;
&lt;br /&gt;
$mystring = &amp;quot;&amp;quot;;&lt;br /&gt;
for($i=0; $i&amp;lt;count($myarray); $i++){&lt;br /&gt;
	$mystring .= $i.&amp;quot;: &amp;quot;.$myarray[$i].&amp;quot;, &amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
echo $mystring;   # displays 0: Apple, 1: Banana, 2: Cherry, 3: Grapefruit&lt;br /&gt;
&lt;br /&gt;
$mystring = &amp;quot;&amp;quot;;&lt;br /&gt;
foreach($myarray as $key =&amp;gt; $value){&lt;br /&gt;
	$mystring .= $key.&amp;quot;: &amp;quot;.$value;&lt;br /&gt;
}&lt;br /&gt;
echo $mystring;   #displays 0: Apple, 1: Banana, 2: Cherry, 3: Grapefruit&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
Just like with all modern programming languages, you can define your own functions with PHP.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
function add($x, $y){&lt;br /&gt;
	return $x + $y;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
echo add(3, 5);   # displays 8&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A neat shortcut for PHP is that you can specify default parameter values directly in the argument list:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
function sayHello($name=&amp;quot;John Doe&amp;quot;){&lt;br /&gt;
	return &amp;quot;Hello, $name... how do you do?&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
echo sayHello(&amp;quot;Todd&amp;quot;);   # displays Hello, Todd... how do you do?&lt;br /&gt;
echo sayHello();   # displays Hello, John Doe... how do you do?&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Object-Oriented Programming ===&lt;br /&gt;
&lt;br /&gt;
PHP5 supports object-oriented programming, and many new libraries come as classes rather than simple functions.  Here is an example class definition:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
class Food {&lt;br /&gt;
	protected $name;&lt;br /&gt;
	&lt;br /&gt;
	function __construct($name){&lt;br /&gt;
		$this-&amp;gt;name = $name;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	static function getDefinition(){&lt;br /&gt;
		return &amp;quot;Food is nourishment for carbon-based lifeforms.&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	function formatName(){&lt;br /&gt;
		return &amp;quot;Gotta love to eat &amp;quot; . $this-&amp;gt;name;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
class Fruit extends Food {&lt;br /&gt;
	function formatName(){&lt;br /&gt;
		return Food::formatName() . &amp;quot; (fruit)&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$fruit = new Fruit(&amp;quot;Cherry&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
echo $fruit-&amp;gt;formatName() . &amp;quot;\n&amp;quot;;   # displays: Gotta love to eat Cherry (fruit)&lt;br /&gt;
&lt;br /&gt;
echo Fruit::getDefinition() . &amp;quot;\n&amp;quot;;   # displays: Food is nourishment for carbon-based lifeforms.&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Things to notice:&lt;br /&gt;
&lt;br /&gt;
* All methods in a class must be preceded by the function keyword.&lt;br /&gt;
* Static methods require the '''static''' keyword&lt;br /&gt;
* Instance methods can refer to the current instance through the implicit variable '''$this'''&lt;br /&gt;
* To access properties and methods from an instance, use an arrow: '''$instance-&amp;gt;property'''&lt;br /&gt;
* To access static properties and methods from a class, use two colons: '''ClassName::StaticPropertyOrMethod'''&lt;br /&gt;
* Instances of classes are defined using the syntax '''$instance = new ClassName();''' like in Java&lt;br /&gt;
&lt;br /&gt;
== Outputting Data ==&lt;br /&gt;
&lt;br /&gt;
What's the point of a web language if we can't output data?  The most basic method for outputting data is using either the '''echo''' or '''print''' statement:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
echo &amp;quot;Hello World&amp;quot;;   # outputs Hello World to the browser&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You often find yourself wanting to print all information associated with a variable for debugging purposes.  PHP provides the handy '''var_dump''' function for that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
var_dump($myvar);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Content Type ===&lt;br /&gt;
&lt;br /&gt;
PHP is just a factory for generating documents.  We've so far seen it create HTML documents, but it can just as easily create images, PDFs, or any other type of interpreted file format.  Each of these files formats has a '''MIME Type''' associated with it.  To specify a MIME type for a page served over HTTP, the &amp;lt;code&amp;gt;Content-Type&amp;lt;/code&amp;gt; header must be set.&lt;br /&gt;
&lt;br /&gt;
This brings up an important point.  '''Every PHP document has an implicit &amp;lt;code&amp;gt;Content-Type: text/html&amp;lt;/code&amp;gt; header.'''  This means that by default, PHP will generate HTML documents.  '''The MIME type for a document can be changed using the header() function:'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
header(&amp;quot;Content-Type: text/plain&amp;quot;);&lt;br /&gt;
echo time();&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above example creates a plain text file containing the current timestamp (number of seconds since January 1, 1970).&lt;br /&gt;
&lt;br /&gt;
For another application of the Content-Type header, see [[#Sending a File to the Browser]]&lt;br /&gt;
&lt;br /&gt;
=== sprintf() ===&lt;br /&gt;
&lt;br /&gt;
Code in PHP that outputs information can get very ugly.  Consider, for example, the following snippet:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$medals = array(&lt;br /&gt;
	&amp;quot;United States&amp;quot; =&amp;gt; array(46, 29, 29),&lt;br /&gt;
	&amp;quot;China&amp;quot; =&amp;gt; array(38, 27, 23),&lt;br /&gt;
	&amp;quot;Russia&amp;quot; =&amp;gt; array(24, 26, 32)&lt;br /&gt;
);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
	&amp;lt;tr&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Country&amp;lt;/th&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Gold Medals&amp;lt;/th&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Silver Medals&amp;lt;/th&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Bronze Medals&amp;lt;/th&amp;gt;&lt;br /&gt;
	&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
foreach($medals as $country =&amp;gt; $counts){&lt;br /&gt;
	echo &amp;quot;\t&amp;lt;tr&amp;gt;\n\t\t&amp;lt;td&amp;gt;&amp;quot;.htmlentities($country).&amp;quot;&amp;lt;/td&amp;gt;\n\t\t&amp;lt;td&amp;gt;&amp;quot;.htmlentities($counts[0]).&amp;quot;&amp;lt;/td&amp;gt;\n\t\t&amp;lt;td&amp;gt;&amp;quot;.htmlentities($counts[1]).&amp;quot;&amp;lt;/td&amp;gt;\n\t\t&amp;lt;td&amp;gt;&amp;quot;.htmlentities($counts[2]).&amp;quot;&amp;lt;/td&amp;gt;\n\t&amp;lt;/tr&amp;gt;\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This code will generate the following HTML:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
	&amp;lt;tr&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Country&amp;lt;/th&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Gold Medals&amp;lt;/th&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Silver Medals&amp;lt;/th&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Bronze Medals&amp;lt;/th&amp;gt;&lt;br /&gt;
	&amp;lt;/tr&amp;gt;&lt;br /&gt;
	&amp;lt;tr&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;United States&amp;lt;/td&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;46&amp;lt;/td&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;29&amp;lt;/td&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;29&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;/tr&amp;gt;&lt;br /&gt;
	&amp;lt;tr&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;China&amp;lt;/td&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;38&amp;lt;/td&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;27&amp;lt;/td&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;23&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;/tr&amp;gt;&lt;br /&gt;
	&amp;lt;tr&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;Russia&amp;lt;/td&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;24&amp;lt;/td&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;26&amp;lt;/td&amp;gt;&lt;br /&gt;
		&amp;lt;td&amp;gt;32&amp;lt;/td&amp;gt;&lt;br /&gt;
	&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It's not very clear, though, that this is what the PHP code is going to generate.  In particular, the ''echo'' line inside the ''foreach'' loop is 196 jumbled characters!&lt;br /&gt;
&lt;br /&gt;
'''sprintf()''' is a nifty PHP function (with roots in C) that allows us to clean up that code.  We get the same output as above if we use the following PHP instead:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$medals = array(&lt;br /&gt;
	&amp;quot;United States&amp;quot; =&amp;gt; array(46, 29, 29),&lt;br /&gt;
	&amp;quot;China&amp;quot; =&amp;gt; array(38, 27, 23),&lt;br /&gt;
	&amp;quot;Russia&amp;quot; =&amp;gt; array(24, 26, 32)&lt;br /&gt;
);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
	&amp;lt;tr&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Country&amp;lt;/th&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Gold Medals&amp;lt;/th&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Silver Medals&amp;lt;/th&amp;gt;&lt;br /&gt;
		&amp;lt;th&amp;gt;Bronze Medals&amp;lt;/th&amp;gt;&lt;br /&gt;
	&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
foreach($medals as $country =&amp;gt; $counts){&lt;br /&gt;
	echo sprintf(&amp;quot;\t&amp;lt;tr&amp;gt;\n\t\t&amp;lt;td&amp;gt;%s&amp;lt;/td&amp;gt;\n\t\t&amp;lt;td&amp;gt;%d&amp;lt;/td&amp;gt;\n\t\t&amp;lt;td&amp;gt;%d&amp;lt;/td&amp;gt;\n\t\t&amp;lt;td&amp;gt;%d&amp;lt;/td&amp;gt;\n\t&amp;lt;/tr&amp;gt;\n&amp;quot;,&lt;br /&gt;
		htmlentities($country),&lt;br /&gt;
		$counts[0],&lt;br /&gt;
		$counts[1],&lt;br /&gt;
		$counts[2]&lt;br /&gt;
	);&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code is more straightforward and self-explanatory than the first example, and it is also easier to edit and maintain.&lt;br /&gt;
&lt;br /&gt;
Here's how '''sprintf()''' works.  The first argument is a ''format string''.  A format string can contain ''conversion specifications'' for additional data that will be inserted into the format string.  The most common conversion specifications are:&lt;br /&gt;
&lt;br /&gt;
* '''%s''' for a string&lt;br /&gt;
* '''%d''' for a signed integer&lt;br /&gt;
* '''%u''' for an unsigned integer&lt;br /&gt;
* '''%f''' for a floating-point number&lt;br /&gt;
** '''%.2f''' for a floating-point number with 2 decimal places&lt;br /&gt;
* '''%%''' for a literal percentage sign&lt;br /&gt;
&lt;br /&gt;
For more detail on sprintf formats, refer to [http://us.php.net/sprintf the PHP documentation].&lt;br /&gt;
&lt;br /&gt;
The remaining arguments are the data that are inserted into each of the conversion specifications.  In the example above, there are four conversion specifications ('''%s''', '''%d''', '''%d''', and '''%d'''), so '''sprintf()''' takes 4 additional arguments after the format string.&lt;br /&gt;
&lt;br /&gt;
Note that we still need to sanitize string output (using '''htmlentities()''' ) when we are using '''sprintf()'''.  However, since our format string specifies integers for the remaining three arguments, '''sprintf()''' will take care of type casting, so we no longer need to worry about sanitizing the integers.&lt;br /&gt;
&lt;br /&gt;
An additional tip: '''printf()''' is a shortcut for '''echo sprintf()'''.  That is, the following lines are functionally equivalent:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$n = 12345.678;&lt;br /&gt;
printf(&amp;quot;%.2f\n&amp;quot;, $n); // prints 12345.68&lt;br /&gt;
echo sprintf(&amp;quot;%.2f\n&amp;quot;, $n); // also prints 12345.68&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Passing Variables ==&lt;br /&gt;
&lt;br /&gt;
Input values can be passed to a script either through the URL request line or through data submitted by a form. Built in arrays $_GET['var'] and $_POST['var'] return the value of ''var'' depending on the access method. As we will see in the next section, values can also be passed through session variables. Finally, you can use cookies to store and retrieve values. &lt;br /&gt;
&lt;br /&gt;
Note that upon submitting a form, the page specified in the form tag's action attribute is loaded (with variables sent via post or get).&lt;br /&gt;
&lt;br /&gt;
=== GET: Passing Variables via URL ===&lt;br /&gt;
&lt;br /&gt;
If you want to pass values in a URL, the format is &amp;lt;nowiki&amp;gt;''http://example.com/yourphpfile.php?var1=value1&amp;amp;var2=value2.....''&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
PHP saves URL variables in the associative array '''$_GET'''.&lt;br /&gt;
&lt;br /&gt;
For example, the following PHP document would print a hello message according to a name given in the URL.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Hello World&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$name = $_GET['name'];&lt;br /&gt;
&lt;br /&gt;
printf(&amp;quot;&amp;lt;p&amp;gt;Hello, %s; how do you do?&amp;lt;/p&amp;gt;\n&amp;quot;,&lt;br /&gt;
	htmlentities($name)&lt;br /&gt;
);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you access the URL like this: ''greeting.php?name=Alice'', it will show ''Hello, Alice; how do you do?''&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Before we output the name, we pass it through '''htmlentities()''', which sanitizes it for output to the HTML document.  This is necessary because if we displayed the name verbatim from the URL, the name could be ''anything'': that includes malicious code that could be run on a victim's computer!  You will learn more about this type of cyberattack, called '''Cross-Site Scripting''', in Module 4.  For now, just know that whenever you display anything to the end user, you need to pass it through '''htmlentities()'''.&lt;br /&gt;
&lt;br /&gt;
=== POST: Passing Variables via Form ===&lt;br /&gt;
&lt;br /&gt;
Another method for passing variables from page to page is by sending it via POST variables.  Like with GET, POST variables are saved in an associative array, this time named '''$_POST'''.&lt;br /&gt;
&lt;br /&gt;
Consider the following form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Hello World&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;info.php&amp;quot; method=&amp;quot;POST&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&lt;br /&gt;
		&amp;lt;label for=&amp;quot;firstnameinput&amp;quot;&amp;gt;First Name:&amp;lt;/label&amp;gt;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;firstname&amp;quot; id=&amp;quot;firstnameinput&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;/p&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&lt;br /&gt;
		&amp;lt;label for=&amp;quot;lastnameinput&amp;quot;&amp;gt;Last Name:&amp;lt;/label&amp;gt;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;lastname&amp;quot; id=&amp;quot;lastnameinput&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;/p&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&lt;br /&gt;
		&amp;lt;label for=&amp;quot;birthyearinput&amp;quot;&amp;gt;Birth Year:&amp;lt;/label&amp;gt;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;number&amp;quot; name=&amp;quot;birthyear&amp;quot; id=&amp;quot;birthyearinput&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;/p&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&lt;br /&gt;
		&amp;lt;strong&amp;gt;Gender:&amp;lt;/strong&amp;gt;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;radio&amp;quot; name=&amp;quot;gender&amp;quot; value=&amp;quot;male&amp;quot; id=&amp;quot;maleinput&amp;quot; /&amp;gt; &amp;lt;label for=&amp;quot;maleinput&amp;quot;&amp;gt;Male&amp;lt;/label&amp;gt; &amp;amp;nbsp;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;radio&amp;quot; name=&amp;quot;gender&amp;quot; value=&amp;quot;female&amp;quot; id=&amp;quot;femaleinput&amp;quot; /&amp;gt; &amp;lt;label for=&amp;quot;femaleinput&amp;quot;&amp;gt;Female&amp;lt;/label&amp;gt;&lt;br /&gt;
	&amp;lt;/p&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Send&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;reset&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For more information on the HTML markup in the above example, refer to [[HTML and CSS|the HTML and CSS guide]].&lt;br /&gt;
&lt;br /&gt;
This submits a form with POST data to '''info.php'''.  Inside '''info.php''', the provided values will be available in the associative $_POST array under the keys ''firstname'', ''lastname'', ''birthyear'', and ''gender''.&lt;br /&gt;
&lt;br /&gt;
To display the submitted input on a target page, '''info.php''' could contain:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Person Information&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$first = $_POST['firstname'];&lt;br /&gt;
$last = $_POST['lastname'];&lt;br /&gt;
$birthyear = (int) $_POST['birthyear'];&lt;br /&gt;
$gender = $_POST['gender'];&lt;br /&gt;
$age = 2012 - $birthyear;&lt;br /&gt;
&lt;br /&gt;
printf(&amp;quot;&amp;lt;p&amp;gt;Hello, %s %s!  You were born in %d, so you are %d years old.  You are %s.&amp;lt;/p&amp;gt;\n&amp;quot;,&lt;br /&gt;
	htmlentities($first),&lt;br /&gt;
	htmlentities($last),&lt;br /&gt;
	$birthyear,&lt;br /&gt;
	$age,&lt;br /&gt;
	htmlentities($gender)&lt;br /&gt;
);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' It is ''very'' important that you always sanitize strings that you output to the browser using '''htmlentities()''' or a similar function.  If you don't, your site will be vulnerable to all sorts of malware.  For more information, refer to the [[Web Application Security, Part 1|Web Application Security]] guide.&lt;br /&gt;
&lt;br /&gt;
For further help with using HTML forms with PHP, we recommend [http://www.tizag.com/phpT/forms.php this tutorial].&lt;br /&gt;
&lt;br /&gt;
=== Self-Submitting Forms ===&lt;br /&gt;
&lt;br /&gt;
Oftentimes we don't want to pass form values to a different page, but rather to the same page as contains the form so that we can process the information and display output on that same page.  To do this, you can simply omit the '''action''' parameter from the form.  Alternatively, you can use a PHP environment variable like $_SERVER['PHP_SELF'].&lt;br /&gt;
&lt;br /&gt;
The following example simply takes the data input from a form and, via POST variables, echoes it back to the user as bold text on the same page:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Bold Printer&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
&amp;lt;form action=&amp;quot;&amp;lt;?php echo htmlentities($_SERVER['PHP_SELF']); ?&amp;gt;&amp;quot; method=&amp;quot;POST&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&lt;br /&gt;
		&amp;lt;label for=&amp;quot;name&amp;quot;&amp;gt;Name:&amp;lt;/label&amp;gt;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;name&amp;quot; id=&amp;quot;name&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;/p&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Print in Bold&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
if(isset($_POST['name'])){&lt;br /&gt;
	printf(&amp;quot;&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;%s&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;\n&amp;quot;,&lt;br /&gt;
		htmlentities($_POST['name'])&lt;br /&gt;
	);&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sessions ==&lt;br /&gt;
&lt;br /&gt;
If you need to keep track of information associated with a user between page loads, you should use a ''session''.  Sessions are excellent for keeping track of the currently-logged-in user, for example.&lt;br /&gt;
&lt;br /&gt;
PHP makes session management dirt simple.  Whenever you need to use session variables, simply call '''session_start()'''.  Then, you may interact with the $_SESSION associative array, and PHP will take care of accessing and saving all session variables for you!&lt;br /&gt;
&lt;br /&gt;
For example, the following page will display a number, and then double that number on each page reload:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
session_start();&lt;br /&gt;
 &lt;br /&gt;
$oldnum = (int) $_SESSION['inc_num'];&lt;br /&gt;
if($oldnum&amp;lt;1) $oldnum=1;&lt;br /&gt;
$newnum = $oldnum*2;&lt;br /&gt;
 &lt;br /&gt;
echo $newnum;&lt;br /&gt;
$_SESSION['inc_num'] = $newnum;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sessions also work across different pages, as long as they are on the same web server.&lt;br /&gt;
&lt;br /&gt;
'''Tip:''' To log out a user, you can call '''session_destroy()''' after '''session_start()''' on the logout page.&lt;br /&gt;
&lt;br /&gt;
== Other PHP Tips ==&lt;br /&gt;
&lt;br /&gt;
=== Redirecting to a Different Page ===&lt;br /&gt;
&lt;br /&gt;
If you want to redirect the user to a different page, you need to send a '''Location''' header.  For example, a page containing only this code would redirect the user to the ''login.php'' file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
header(&amp;quot;Location: login.php&amp;quot;);&lt;br /&gt;
exit;   // we call exit here so that the script will stop executing before the connection is broken&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is often useful to perform redirects after you perform server-side operations.&lt;br /&gt;
&lt;br /&gt;
'''Important:''' You should generally not leave a user sitting on a page that has POST data, because if they refresh the page, their POST data will be submitted again, causing your server to perform an action twice.  Rather, you should perform the operation, and then redirect them to another page that does not contain POST data in the header.&lt;br /&gt;
&lt;br /&gt;
=== Reading a File Line-by-Line ===&lt;br /&gt;
&lt;br /&gt;
If you want to read a file line-by-line, open a file handler using '''fopen()''', use '''fgets()''' to read lines until you've reached the end, and then close the file using '''fclose()'''.&lt;br /&gt;
&lt;br /&gt;
The following example reads '''file_with_lines.txt''' and outputs its content in an unordered list, where each list item is a line in the file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
$h = fopen(&amp;quot;file_with_lines.txt&amp;quot;, &amp;quot;r&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
$linenum = 1;&lt;br /&gt;
echo &amp;quot;&amp;lt;ul&amp;gt;\n&amp;quot;;&lt;br /&gt;
while( !feof($h) ){&lt;br /&gt;
	printf(&amp;quot;\t&amp;lt;li&amp;gt;Line %d: %s&amp;lt;/li&amp;gt;\n&amp;quot;,&lt;br /&gt;
		$linenum++,&lt;br /&gt;
		fgets($h)&lt;br /&gt;
	);&lt;br /&gt;
}&lt;br /&gt;
echo &amp;quot;&amp;lt;/ul&amp;gt;\n&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
fclose($h);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Most files in Linux end with an empty line, so the very last iteration of the above loop will output an empty bullet point.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' The function '''fgets()''' reads the contents of a line ''in addition to the line feed at the end of the line''.  If you want to compare a string to the line that was read by '''fgets()''', you need to pass the value returned by '''fgets()''' to a function like '''[http://php.net/trim trim()]'''.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' If you want to read an entire file, PHP provides the '''file_get_contents()''' function, which is basically a shortcut for '''fopen()''', '''fread()''', and '''fclose()'''.  ('''fread()''' is similar to '''fgets()''', except it reads the entire file instead of just one line.)&lt;br /&gt;
&lt;br /&gt;
=== Sending a File to the Browser ===&lt;br /&gt;
&lt;br /&gt;
Another useful function to know is the '''readfile''' function. It takes a file on the webserver's file system and sends it to the web browser. A simple example is given below, but note that you'll probably need to specify addition header fields in order to have the web browser download the file correctly.&lt;br /&gt;
&lt;br /&gt;
The following example loads a file associated with a certain username and displays it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
session_start();&lt;br /&gt;
&lt;br /&gt;
$filename = $_GET['file'];&lt;br /&gt;
&lt;br /&gt;
// We need to make sure that the filename is in a valid format; if it's not, display an error and leave the script.&lt;br /&gt;
// To perform the check, we will use a regular expression.&lt;br /&gt;
if( !preg_match('/^[\w_\.\-]+$/', $filename) ){&lt;br /&gt;
	echo &amp;quot;Invalid filename&amp;quot;;&lt;br /&gt;
	exit;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Get the username and make sure that it is alphanumeric with limited other characters.&lt;br /&gt;
// You shouldn't allow usernames with unusual characters anyway, but it's always best to perform a sanity check&lt;br /&gt;
// since we will be concatenating the string to load files from the filesystem.&lt;br /&gt;
$username = $_SESSION['username'];&lt;br /&gt;
if( !preg_match('/^[\w_\-]+$/', $username) ){&lt;br /&gt;
	echo &amp;quot;Invalid username&amp;quot;;&lt;br /&gt;
	exit;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$full_path = sprintf(&amp;quot;/srv/uploads/%s/%s&amp;quot;, $username, $filename);&lt;br /&gt;
&lt;br /&gt;
// Now we need to get the MIME type (e.g., image/jpeg).  PHP provides a neat little interface to do this called finfo.&lt;br /&gt;
$finfo = new finfo(FILEINFO_MIME_TYPE);&lt;br /&gt;
$mime = $finfo-&amp;gt;file($full_path);&lt;br /&gt;
&lt;br /&gt;
// Finally, set the Content-Type header to the MIME type of the file, and display the file.&lt;br /&gt;
header(&amp;quot;Content-Type: &amp;quot;.$mime);&lt;br /&gt;
header('content-disposition: inline; filename=&amp;quot;'.$filename.'&amp;quot;;');&lt;br /&gt;
readfile($full_path);&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Uploading a File ===&lt;br /&gt;
&lt;br /&gt;
Uploading files is similar to submitting data in forms.  For starters, you need a form that submits to your uploading script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form enctype=&amp;quot;multipart/form-data&amp;quot; action=&amp;quot;uploader.php&amp;quot; method=&amp;quot;POST&amp;quot;&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;MAX_FILE_SIZE&amp;quot; value=&amp;quot;20000000&amp;quot; /&amp;gt;&lt;br /&gt;
		&amp;lt;label for=&amp;quot;uploadfile_input&amp;quot;&amp;gt;Choose a file to upload:&amp;lt;/label&amp;gt; &amp;lt;input name=&amp;quot;uploadedfile&amp;quot; type=&amp;quot;file&amp;quot; id=&amp;quot;uploadfile_input&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;/p&amp;gt;&lt;br /&gt;
	&amp;lt;p&amp;gt;&lt;br /&gt;
		&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Upload File&amp;quot; /&amp;gt;&lt;br /&gt;
	&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that we need to specify &amp;lt;code&amp;gt;enctype=&amp;quot;multipart/form-data&amp;quot;&amp;lt;/code&amp;gt; on the form.  This is to enable files to be uploaded and recognized by PHP.&lt;br /&gt;
&lt;br /&gt;
PHP puts all files submitted with a form into the '''$_FILES''' superglobal array.  Each entry in the $_FILES array contains the following information:&lt;br /&gt;
&lt;br /&gt;
* '''$_FILES['uploadedfile']['name']''' is the original name of the file on the client's machine&lt;br /&gt;
* '''$_FILES['uploadedfile']['type']''' is the MIME type of the file according to the browser (don't take it for granted)&lt;br /&gt;
* '''$_FILES['uploadedfile']['size']''' is the size, in bytes, of the uploaded file&lt;br /&gt;
* '''$_FILES['uploadedfile']['tmp_name']''' is the temporary location on your filesystem where Apache saved the uploaded file&lt;br /&gt;
* '''$_FILES['uploadedfile']['error']''' is the error code associated with the file upload (if applicable)&lt;br /&gt;
&lt;br /&gt;
To upload the file submitted by the form above in a user's special folder, we could use the following PHP code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
session_start();&lt;br /&gt;
&lt;br /&gt;
// Get the filename and make sure it is valid&lt;br /&gt;
$filename = basename($_FILES['uploadedfile']['name']);&lt;br /&gt;
if( !preg_match('/^[\w_\.\-]+$/', $filename) ){&lt;br /&gt;
	echo &amp;quot;Invalid filename&amp;quot;;&lt;br /&gt;
	exit;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// Get the username and make sure it is valid&lt;br /&gt;
$username = $_SESSION['username'];&lt;br /&gt;
if( !preg_match('/^[\w_\-]+$/', $username) ){&lt;br /&gt;
	echo &amp;quot;Invalid username&amp;quot;;&lt;br /&gt;
	exit;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$full_path = sprintf(&amp;quot;/srv/uploads/%s/%s&amp;quot;, $username, $filename);&lt;br /&gt;
&lt;br /&gt;
if( move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $full_path) ){&lt;br /&gt;
	header(&amp;quot;Location: upload_success.html&amp;quot;);&lt;br /&gt;
	exit;&lt;br /&gt;
}else{&lt;br /&gt;
	header(&amp;quot;Location: upload_failure.html&amp;quot;);&lt;br /&gt;
	exit;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' A lot of the code above is the same as the code in the file download example.  In your project, you should save the logic of generating the file path (in a function) in a third file that you include into the upload and download scripts.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' By default, PHP will not allow a file upload of more than 2 MB.  SitePoint has an excellent tutorial for how to increase this limit: http://www.sitepoint.com/upload-large-files-in-php/&lt;br /&gt;
&lt;br /&gt;
== PEAR ==&lt;br /&gt;
&lt;br /&gt;
The PHP Extension and Application Repository, or '''PEAR''', is a package manager that enables you to install classes and/or extensions to PHP.  In other words, it is a yum/apt for PHP.  You can think of PEAR as PHP's analog of ''gem'' in Ruby or ''pip'' in Python.&lt;br /&gt;
&lt;br /&gt;
=== Configuration ===&lt;br /&gt;
&lt;br /&gt;
PEAR is available through both the yum and apt repositories under the package name '''php-pear'''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo yum install php-pear  # in RHEL&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Installing PHP Extensions ===&lt;br /&gt;
&lt;br /&gt;
Using PEAR to install PHP extensions is just as easy as yum, apt, gem, and pip.  Just run '''sudo pear install xxx'''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo pear install Archive_Tar&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Go here for a list of available packages in PEAR: http://pear.php.net/packages.php&lt;br /&gt;
&lt;br /&gt;
=== Using PHP Extensions ===&lt;br /&gt;
&lt;br /&gt;
To make use an extension installed in PEAR, you must '''include''' or '''require''' it into the PHP file of interest.  For example, if you wanted to use the Archive_Tar class from the above example in a PHP file, you would do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
require &amp;quot;Archive/Tar.php&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
// your code here&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By convention, the filepath you need to specify is the name of the PEAR package with underscores replaced with slashes and a .php extension at the end.  For example, the package ''Console_Getargs'' becomes &amp;lt;code&amp;gt;require &amp;quot;Console/Getargs.php&amp;quot;;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== PECL ===&lt;br /&gt;
&lt;br /&gt;
The PHP Extension Community Library, or '''PECL''', is a repository for additional PHP extensions, the difference being that PECL extensions are written in compiled C code rather than PHP.&lt;br /&gt;
&lt;br /&gt;
PECL is installed automatically when you install PEAR from yum or apt-get.&lt;br /&gt;
&lt;br /&gt;
Installing an extension using PECL is almost identical to PEAR, except that you use '''pecl''' instead of '''pear''' on the command prompt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo pecl install imagick&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You do not need to '''require''' or '''include''' PECL extensions since they are already compiled into PHP.&lt;br /&gt;
&lt;br /&gt;
== PHP Reference ==&lt;br /&gt;
&lt;br /&gt;
If you ever have a question about PHP, first check the well-written documentation.  To skip immediately to the documentation on any function, simply visit &amp;lt;nowiki&amp;gt;http://php.net/&amp;lt;/nowiki&amp;gt;'''functionname'''.  For example: http://php.net/var_dump&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 2]]&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=VS_Code&amp;diff=2863</id>
		<title>VS Code</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=VS_Code&amp;diff=2863"/>
		<updated>2023-01-27T20:08:41Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* SFTP Integration (Shipping files to your server) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Getting Started With Each Module ==&lt;br /&gt;
&lt;br /&gt;
* Create Github repo using the CSE 330 repo creator  (Check Piazza for the link)&lt;br /&gt;
* Navigate to the created repo in Github&lt;br /&gt;
* Clone the repo via https to a dedicated folder on your computer&lt;br /&gt;
&lt;br /&gt;
[[File:File-Structure.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* In VS Code, File &amp;gt; Open the Spring2019-module1-individual-STUDENTID '''folder''' that you cloned to your computer&lt;br /&gt;
&lt;br /&gt;
If you followed the above steps correctly, the folder's Git should be configured to your Github repository!  I highly recommend creating your Github repo, cloning the folder to a designated spot, and keeping all modules separated for the semester as shown in the image above.&lt;br /&gt;
&lt;br /&gt;
== Module 1 -- Using the Git Integration ==&lt;br /&gt;
'''Note: If you're using Windows, you may need to install Git on your machine first. https://git-scm.com/download/win . You can check if you have Git running by typing git --version in your terminal'''&lt;br /&gt;
&lt;br /&gt;
* First, open the File Explorer tab on the left, and right click to create a new file, birthday.html&lt;br /&gt;
[[File:New-file.png|400px|center]]&lt;br /&gt;
* Ensure VS Code has it marked as an html file (see the file type next to the smiley face)&lt;br /&gt;
* Type '''doc''' followed by enter, and allow VS Code to generate a basic HTML file for you (use VS Code to your advantage! It can do a lot of your coding for you).&lt;br /&gt;
* Save the file, you should see a popup next to the Version Control symbol on the left. VS Code has detected that your project is different than what it is in your remote Github repo.&lt;br /&gt;
* To commit, simply type a message in the box and click the check mark above it.  To push to your Github repo, click the 3 dots next to the check mark and select 'push'&lt;br /&gt;
* Note this is also where you can pull from your remote.&lt;br /&gt;
&lt;br /&gt;
==== Bonus - Module 1 ====&lt;br /&gt;
* If you like your text editor to look pretty, you can go to the Extensions tab and search for different themes. (Check out the Material theme!)&lt;br /&gt;
* You can view your settings by clicking CMD + , (Mac) or Ctrl + , (Windows).  Search for Theme and choose one that works for you!&lt;br /&gt;
&lt;br /&gt;
== Module 2 == &lt;br /&gt;
=== DISCLAIMER ===&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;There are two SFTP VSCode extensions of the same name. One of them is depreciated. Use the extension distributed by Natizyskunk.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== SFTP Integration (Shipping files to your server) ===&lt;br /&gt;
# Select a folder to use for your work and open it in VSCode. When editing files on your instance, the file will be saved locally in this location for editing and reuploaded&lt;br /&gt;
# Open the Extensions tab and search for 'SFTP'. Download the version distributed by &amp;quot;Natizyskunk&amp;quot;.&lt;br /&gt;
# To use commands in VS Code, type '''Cmd + Shift + P''' (Mac), or '''Ctrl + Shift + P''' on windows. &lt;br /&gt;
# Type SFTP and open the sftp config command. &lt;br /&gt;
&lt;br /&gt;
Your sftp.json file should look like the following:&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;name&amp;quot;: &amp;quot;&amp;lt;My Instance&amp;gt;&amp;quot;,&lt;br /&gt;
    &amp;quot;host&amp;quot;: &amp;quot;&amp;lt;ec2-xxxxx-xxxxxx-xxxxx.amazonaws.com&amp;gt;&amp;quot;,&lt;br /&gt;
    &amp;quot;protocol&amp;quot;: &amp;quot;sftp&amp;quot;,&lt;br /&gt;
    &amp;quot;port&amp;quot;: 22,&lt;br /&gt;
    &amp;quot;username&amp;quot;: &amp;quot;&amp;lt;custom instance username&amp;gt;&amp;quot;&lt;br /&gt;
    &amp;quot;remotePath: &amp;quot;/home/&amp;lt;custom instance username&amp;gt;/&amp;quot;,&lt;br /&gt;
    &amp;quot;uploadOnSave&amp;quot;: true,&lt;br /&gt;
    &amp;quot;privateKeyPath&amp;quot;: &amp;quot;&amp;lt;/path/to/.ssh/id_rsa&amp;gt;&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
- Note the uploadOnSave field is optional, but can be nice!&lt;br /&gt;
- Check the VS Code output for errors in your config.&lt;br /&gt;
&lt;br /&gt;
Additionally: You should notice an SFTP tab on the side of VS Code. Here, you can view the file structure on your server.]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Preventing &amp;quot;Edit in Local&amp;quot; when editing files'''&lt;br /&gt;
&lt;br /&gt;
In order to edit locally, you'll have to right click on the file you wish to edit and select &amp;quot;Edit in local&amp;quot; every time. To avoid this, you can:&lt;br /&gt;
# Open vscode settings by File &amp;gt;&amp;gt; Preferences &amp;gt;&amp;gt; Settings&lt;br /&gt;
# In settings, search for &amp;quot;downloadWhenOpenInRemoteExplorer&amp;quot; and toggle it on&lt;br /&gt;
# restart VScode.&lt;br /&gt;
&lt;br /&gt;
=== Testing Everything Locally ===&lt;br /&gt;
If you would like to avoid having to frequently upload your changes to your instance in order to test your changes, you can optionally set up a local PHP server.&lt;br /&gt;
&lt;br /&gt;
'''To run PHP locally'''&lt;br /&gt;
&lt;br /&gt;
'''Windows'''&lt;br /&gt;
# Download WAMP http://www.wampserver.com/en/download-wampserver-64bits/&lt;br /&gt;
# Place your project repositories in Wamp's www/ directory, and navigate to http://localhost in your browser.  You should see your projects listed here, run php files, and use phpmyadmin.&lt;br /&gt;
&lt;br /&gt;
'''Mac'''&lt;br /&gt;
# Download Homebrew. Homebrew is a great package manager for OSx and we will be using it in future modules. &lt;br /&gt;
# Type the following in your terminal and follow instructions&lt;br /&gt;
 /usr/bin/ruby -e &amp;quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&amp;quot;&lt;br /&gt;
# In your terminal, type '''php -v'''. If your version is less than 7, update with brew. '''brew install php'''&lt;br /&gt;
# In VS Code, search for the extension '''Php Server'''. After installing, use VS Code's command pallette with CMD+Shift+P , search for PHP, and select start server.  You should be able to view your project in your localhost&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_4&amp;diff=2861</id>
		<title>Module 4</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_4&amp;diff=2861"/>
		<updated>2023-01-10T19:34:25Z</updated>

		<summary type="html">&lt;p&gt;Zach: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
In Module 4, you will learn the fundamentals of Python, a popular scripting language, and Regular Expressions, which give you power in text processing.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 4.&lt;br /&gt;
&lt;br /&gt;
== Using the Wiki ==&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
Text enclosed by &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;&amp;lt;&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;&amp;gt;&amp;lt;/syntaxhighlight&amp;gt; should be replaced by content unique to you.&lt;br /&gt;
&lt;br /&gt;
'''Example'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo useradd -r -m -c &amp;quot;&amp;lt;My Full Name&amp;gt;&amp;quot; &amp;lt;usernameHere&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
becomes&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo useradd -r -m -c &amp;quot;Zach Cohn&amp;quot; zcohn&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Reading ==&lt;br /&gt;
&lt;br /&gt;
The following articles on the online class wiki textbook contain information that will help you complete the assignments.&lt;br /&gt;
&lt;br /&gt;
* [[Python]]&lt;br /&gt;
* [[Regular Expressions]]&lt;br /&gt;
* [[FAQ - Mod 4]]&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
=== Learn Python and Regular Expressions ===&lt;br /&gt;
&lt;br /&gt;
Up to this point in CSE 330, you have used only one programming language: PHP.  In Module 4, you will learn a new language: Python.  Before starting this assignment, you should look over the [[Python|online textbook article about Python]].  You should be using version 3 (or greater) of Python. Additionally, you may find it helpful to look over the [[Regular Expressions|online textbook article about Regular Expressions]].&lt;br /&gt;
&lt;br /&gt;
=== Write some Regular Expressions ===&lt;br /&gt;
&lt;br /&gt;
Please write regular expressions that do each the following:&lt;br /&gt;
&lt;br /&gt;
# Match the substring &amp;quot;hello world&amp;quot; in a string.&lt;br /&gt;
# Find all character strings in an input string that contains three or more consecutive vowels, regardless of case.&lt;br /&gt;
# Match an input string that is '''entirely''' a flight code, of the format AA####, where '''AA''' is a two-letter uppercase airline code, and '''####''' is a three- or four-digit flight number.&lt;br /&gt;
Examples:&lt;br /&gt;
   Note: text in ''[[red]]'' is matched by the regular expression. Please note that each line is a '''separate''' test input string. For Regex 3, '''six''' separate test cases are given.&lt;br /&gt;
   Regex 1:  Programmers will often write ''[[hello world]]'' as their first project with a programming language.&lt;br /&gt;
   Regex 2:  The ''[[gooey]]'' peanut butter and jelly sandwich was a ''[[beauty]]''.&lt;br /&gt;
   Regex 3:  ''[[AA312]]''&lt;br /&gt;
             ''[[AA1298]]''&lt;br /&gt;
             ''[[NW1234]]''&lt;br /&gt;
             ''[[US443]]''&lt;br /&gt;
             US31344&lt;br /&gt;
             AA123 extratext&lt;br /&gt;
&lt;br /&gt;
            &lt;br /&gt;
&lt;br /&gt;
Save your regexes to text files – one each.&lt;br /&gt;
&lt;br /&gt;
=== Baseball Stats Counter ===&lt;br /&gt;
&lt;br /&gt;
The St. Louis Cardinals are the most legendary baseball team in the national league.  In this exercise, you will be creating a Python script that reads box scores from a file and computes the Cardinals' players' batting averages in a particular season.&lt;br /&gt;
&lt;br /&gt;
==== Tips and Instructions ====&lt;br /&gt;
&lt;br /&gt;
* You should write a Python script file to solve this problem.&lt;br /&gt;
* You should use a regular expression to parse players' names, at-bats, hits, and runs from the input file.&lt;br /&gt;
* You may want to create a class to hold and compute information about each player.&lt;br /&gt;
* Your file should take one command-line argument: the path to an input file.  If no path is given, your program should print a usage message.&lt;br /&gt;
&lt;br /&gt;
==== Input ====&lt;br /&gt;
&lt;br /&gt;
Sample input files may be found here: http://classes.engineering.wustl.edu/cse330/content/cardinals/&lt;br /&gt;
&lt;br /&gt;
The top of the file contains a citation, and what follows is an entire season of Cardinals Baseball box scores.  Each game starts with a title; for example:&lt;br /&gt;
&lt;br /&gt;
 === St.Louis Cardinals vs. Chicago Cubs, 1940-04-19 ===&lt;br /&gt;
&lt;br /&gt;
What follows are the performance of each player in that game.  The format of each line is as follows:&lt;br /&gt;
&lt;br /&gt;
 XXX batted # times with # hits and # runs&lt;br /&gt;
&lt;br /&gt;
where '''XXX''' is the player's name (you may assume that the name is unique), and each '''#''' are integers representing the number of &amp;quot;at bats&amp;quot;, the number of &amp;quot;hits&amp;quot;, and the number of &amp;quot;runs&amp;quot;, respectively.&lt;br /&gt;
&lt;br /&gt;
==== Output ====&lt;br /&gt;
&lt;br /&gt;
Your script needs to output all players' batting average across the season.  A player's batting average is that player's total hits divided by that player's total at-bats throughout the entire season.  For example, Johnny Hopp was at bat 149 times in 1940, and he had 41 hits, so his batting average was 0.275.&lt;br /&gt;
&lt;br /&gt;
Each line in the output should have the format:&lt;br /&gt;
&lt;br /&gt;
 XXX: #.###&lt;br /&gt;
&lt;br /&gt;
where '''XXX''' is the player's name, and '''#.###''' is the player's batting average, '''rounded''' (not truncated) to three decimal places.&lt;br /&gt;
&lt;br /&gt;
The players should be sorted by batting average, with the highest batting average on top.  If two players have the exact same batting average (before rounding occurs), the order between those two players is unimportant.&lt;br /&gt;
&lt;br /&gt;
For example, the correct output for the 1940 season is:&lt;br /&gt;
&amp;lt;!-- Jimmy Brown was 0.280 and Ira Hutchinson was 0.125 --&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
Pepper Martin: 0.316&lt;br /&gt;
Walker Cooper: 0.316&lt;br /&gt;
Johnny Mize: 0.314&lt;br /&gt;
Ernie Koy: 0.310&lt;br /&gt;
Enos Slaughter: 0.306&lt;br /&gt;
Joe Medwick: 0.304&lt;br /&gt;
Terry Moore: 0.304&lt;br /&gt;
Joe Orengo: 0.286&lt;br /&gt;
Jimmy Brown: 0.280&lt;br /&gt;
Marty Marion: 0.279&lt;br /&gt;
Don Gutteridge: 0.276&lt;br /&gt;
Johnny Hopp: 0.275&lt;br /&gt;
Creepy Crespi: 0.273&lt;br /&gt;
Mickey Owen: 0.265&lt;br /&gt;
Bill DeLancey: 0.250&lt;br /&gt;
Don Padgett: 0.242&lt;br /&gt;
Stu Martin: 0.238&lt;br /&gt;
Eddie Lake: 0.222&lt;br /&gt;
Hal Epps: 0.214&lt;br /&gt;
Lon Warneke: 0.209&lt;br /&gt;
Harry Walker: 0.185&lt;br /&gt;
Max Lanier: 0.179&lt;br /&gt;
Bill McGee: 0.178&lt;br /&gt;
Carl Doyle: 0.174&lt;br /&gt;
Mort Cooper: 0.157&lt;br /&gt;
Clyde Shoun: 0.145&lt;br /&gt;
Carden Gillenwater: 0.130&lt;br /&gt;
Bob Bowman: 0.067&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
We will be grading the following aspects of your work.  There are 50 points total.&lt;br /&gt;
&lt;br /&gt;
'''Assignments (including code) must be committed to Github by the end of class on the due date (commit early and often). Failing to commit by the end of class on the due date will result in a 0. ''' &lt;br /&gt;
&lt;br /&gt;
Upload your baseball code and a file with your Regular expressions.&lt;br /&gt;
&lt;br /&gt;
# '''Regular Expressions (15 Points):'''&lt;br /&gt;
#* '''Your regex files should contain your regex (with no delimiters or flags) and nothing else.'''&lt;br /&gt;
#* Regular Expression 1 Correct and saved in a file named &amp;lt;code&amp;gt;regex1.txt&amp;lt;/code&amp;gt; (5 points)&lt;br /&gt;
#* Regular Expression 2 Correct and saved in a file named &amp;lt;code&amp;gt;regex2.txt&amp;lt;/code&amp;gt;(5 points)&lt;br /&gt;
#* Regular Expression 3 Correct and saved in a file named &amp;lt;code&amp;gt;regex3.txt&amp;lt;/code&amp;gt;(5 points)&lt;br /&gt;
# '''Baseball Stats Counter (35 Points):'''&lt;br /&gt;
#* Solution is written entirely in Python and saved in a file named &amp;lt;code&amp;gt;baseball.py&amp;lt;/code&amp;gt; (8 points)&lt;br /&gt;
#*: ''Note: Failing to write your code in Python 3 will result in losing, at a minimum, points for this category.''&lt;br /&gt;
#* Correct usage of one or more regular expressions to parse and extract data from each line of the input file (8 points)&lt;br /&gt;
#*: ''Note: You should not be using &amp;lt;code&amp;gt;str.split&amp;lt;/code&amp;gt; to extract data.''&lt;br /&gt;
#* Script prints a usage message if a command line argument is not present (4 points)&lt;br /&gt;
#*: ''Note: For an example of a usage message, see [https://en.wikipedia.org/wiki/Usage_message#Examples this link.]''&lt;br /&gt;
#* Output is correct for all test cases (15 points)&lt;br /&gt;
#*: ''This includes sorting and rounding.''&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 4]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=2860</id>
		<title>Module 3</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_3&amp;diff=2860"/>
		<updated>2023-01-10T19:33:42Z</updated>

		<summary type="html">&lt;p&gt;Zach: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
In Module 3, you will learn about MySQL, a web application database.&lt;br /&gt;
&lt;br /&gt;
This article contains your assignments for Module 3.&lt;br /&gt;
&lt;br /&gt;
== Using the Wiki ==&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
Text enclosed by &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;&amp;lt;&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;&amp;gt;&amp;lt;/syntaxhighlight&amp;gt; should be replaced by content unique to you.&lt;br /&gt;
&lt;br /&gt;
'''Example'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo useradd -r -m -c &amp;quot;&amp;lt;My Full Name&amp;gt;&amp;quot; &amp;lt;usernameHere&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
becomes&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo useradd -r -m -c &amp;quot;Zach Cohn&amp;quot; zcohn&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Reading ==&lt;br /&gt;
&lt;br /&gt;
The following articles on the online class wiki textbook contain information that will help you complete the assignments.&lt;br /&gt;
&lt;br /&gt;
* [[Introduction to MySQL]]&lt;br /&gt;
* [[MySQL Schema and State]]&lt;br /&gt;
* [[PHP and MySQL]]&lt;br /&gt;
* [[Web Application Security, Part 2]]&lt;br /&gt;
* [[FAQ - Mod 3]]&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
You will create a simple grades database containing four tables.&lt;br /&gt;
&lt;br /&gt;
'''IMPORTANT:''' The individual assignment is to be done by writing queries by hand.  (You can use phpMyAdmin to run the queries, but '''do not let phpMyAdmin write your queries for you!''')  Writing your own queries gives you a greater understanding of the underlying mechanisms and databases in general.  Additionally, having SQL knowledge and experience is a very marketable trait.&lt;br /&gt;
&lt;br /&gt;
=== Install MySQL and phpMyAdmin ===&lt;br /&gt;
&lt;br /&gt;
Before you start, '''you need to install MySQL''' on your EC2 instance.  You may also install phpMyAdmin, a web frontend to MySQL, if you choose to do so. Instructions to install both can be found on the [[Introduction to MySQL]] page.&lt;br /&gt;
&lt;br /&gt;
=== Set Up a Database ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[Introduction to MySQL#Managing Databases]]&lt;br /&gt;
&lt;br /&gt;
# Create a database named '''wustl''' &lt;br /&gt;
# Create a user named '''wustl_inst''' and give them the password '''wustl_pass'''&lt;br /&gt;
&lt;br /&gt;
=== Create Tables ===&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
When creating tables, keep the following items in mind:&lt;br /&gt;
&lt;br /&gt;
* You should create all tables such that they use the InnoDB storage engine, since we wish to make use of its support of foreign keys. In other database engines, foreign key constraints are not enforced.  (If you mess up, you can use ALTER TABLE to change the storage engine.)&lt;br /&gt;
* Where it is appropriate, you should take advantage of the ability to define fields NOT NULL so that you do not inadvertently insert incomplete data for a row.&lt;br /&gt;
&lt;br /&gt;
Create the following tables:&lt;br /&gt;
&lt;br /&gt;
# Create a table named '''students''' with the following fields:&lt;br /&gt;
#* '''id''' of an appropriately-sized unsigned integer type (we will never need to process more than a million students)&lt;br /&gt;
#* '''first_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''last_name''' of type '''VARCHAR(50)'''&lt;br /&gt;
#* '''email_address''' of type '''VARCHAR(50)'''&lt;br /&gt;
#: The primary key should be on the '''id''' field.&lt;br /&gt;
# Create a table named '''departments''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM''' (e.g. &amp;quot;L&amp;quot; for ArtSci and &amp;quot;E&amp;quot; for Engineering).  The options are as follows:&lt;br /&gt;
#*: 'L', 'B', 'A', 'F', 'E', 'T', 'I', 'W', 'S', 'U', 'M'&lt;br /&gt;
#* '''dept_id''' of an appropriately-sized unsigned integer type (in the foreseeable future there will never be more than 200 departments in a school)&lt;br /&gt;
#* '''abbreviation''' of type '''VARCHAR(9)''' (e.g. CSE, ChemE, etc)&lt;br /&gt;
#* '''dept_name''' of type '''VARCHAR(200)''' (e.g. Computer Science and Engineering)&lt;br /&gt;
#: The primary key should be on two fields: '''school_code''' and '''dept_id'''&lt;br /&gt;
#: '''Note:''' Why not just use the department ID for the primary key? The ID numbers are sometimes reused across schools. For instance, department 33 in The College of Arts and Sciences is Psychology while department 33 in The School of Engineering and Applied Sciences is Energy, Environmental and Chemical Engineering. Thus we must also include the school code to differentiate them  such that the record for  E33 is distinct from that of L33.&lt;br /&gt;
# Create a table named '''courses''' with the following fields:&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: This should have the same letters in the same order as the '''school_code''' '''ENUM''' field in the '''departments''' table.&lt;br /&gt;
#* '''dept_id''' of the same size of integer as in the '''departments''' table&lt;br /&gt;
#* '''course_code''' of type '''CHAR(5)''' (this will hold course codes; e.g., '330S', '131', '2960')&lt;br /&gt;
#* '''name''' of type '''VARCHAR(150)'''&lt;br /&gt;
#: The appropriate fields in this table should make a foreign key reference to the corresponding fields in '''department'''.&lt;br /&gt;
#: In addition, it is up to you to determine the field(s) for the primary key.&lt;br /&gt;
#: '''Note:''' If you are unsure which fields to make the foreign keys and feel the need to beg your friends or the TAs to give you the answer, we recommend exercising reason and common sense.&lt;br /&gt;
# Create a table named '''grades''' with the following fields:&lt;br /&gt;
#* '''pk_grade_ID''' of an appropriately-sized unsigned integer type (should be larger than the one you chose for the '''students''' table). There will never be more than 1,000 grades per student.&lt;br /&gt;
#*: You should declare this field to be '''auto_increment''' and make it the primary key.&lt;br /&gt;
#*: This is called a ''surrogate key'' as opposed to a ''natural key'' because it doesn't arise &amp;quot;naturally&amp;quot; from the data; that is to say that it is not derived from application data. The use of surrogate keys vs. natural keys is a polemic issue amongst database designers.  For a decently unbiased take on the issue, see this page: http://www.agiledata.org/essays/keys.html#Comparison&lt;br /&gt;
#*: '''Food for thought:''' Aside from simply exposing you to the concept, can you think of any reasons why a surrogate key might be preferable for this table?  Alternatively, what attributes, if any, could you use as a natural key, and what might be the drawbacks of doing so?&lt;br /&gt;
#* '''student_id''' of the same integer (unsigned) type that you chose in the '''students''' table&lt;br /&gt;
#* '''grade''' of type '''decimal(5,2)'''&lt;br /&gt;
#* '''school_code''' of type '''ENUM'''&lt;br /&gt;
#*: Can you guess what entries to use for the enum?&lt;br /&gt;
#* '''dept_id''' of the same integer type that you've used for this field in other tables&lt;br /&gt;
#* '''course_code''' of the same type you chose for the course code in the '''courses''' table&lt;br /&gt;
#: The '''grades''' table should have foreign keys to both the '''students''' table and the '''courses''' table.&lt;br /&gt;
&lt;br /&gt;
=== Populate Tables ===&lt;br /&gt;
&lt;br /&gt;
Now, populate the tables by downloading the text files given below and loading them into the appropriate tables.&lt;br /&gt;
&lt;br /&gt;
'''Note:''' Do not insert all the values manually; instead, use the MySQL's ability to load in data from text files.&lt;br /&gt;
&lt;br /&gt;
You may find the following article to be very helpful: [[MySQL Schema and State]]&lt;br /&gt;
&lt;br /&gt;
The files containing the data are:&lt;br /&gt;
* students: https://classes.engineering.wustl.edu/cse330/content/students_data.txt&lt;br /&gt;
* courses: https://classes.engineering.wustl.edu/cse330/content/courses.txt&lt;br /&gt;
* departments: https://classes.engineering.wustl.edu/cse330/content/departments_data.txt&lt;br /&gt;
* grades: https://classes.engineering.wustl.edu/cse330/content/grades_data.txt&lt;br /&gt;
&lt;br /&gt;
=== Insert More Data ===&lt;br /&gt;
&lt;br /&gt;
Insert the following data into the tables that you have created and populated:&lt;br /&gt;
&lt;br /&gt;
# Insert entries for CSE 330S, CSE 131, and CSE 260M.&lt;br /&gt;
#: ''If you don't know CSE's department code, how can you find out using the tables in the database?''&lt;br /&gt;
# Insert the grades given for the students named below. &lt;br /&gt;
#* '''Ben Harper'''&lt;br /&gt;
#** E-mail: '''bharper@ffym.com'''&lt;br /&gt;
#** Student ID: '''88'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 35.5 in CSE 330S&lt;br /&gt;
#*** 0 in CSE 131&lt;br /&gt;
#*** 95 in CSE 260M&lt;br /&gt;
#* '''Matt Freeman'''&lt;br /&gt;
#** E-mail: '''mfreeman@kickinbassist.net'''&lt;br /&gt;
#** Student ID: '''202'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 100 in CSE 330S&lt;br /&gt;
#*** 90.5 in CSE 131&lt;br /&gt;
#*** 94.8 in CSE 260M&lt;br /&gt;
#* '''Marc Roberge'''&lt;br /&gt;
#** E-mail: '''mroberge@ofarevolution.us'''&lt;br /&gt;
#** Student ID: '''115'''&lt;br /&gt;
#** Grades:&lt;br /&gt;
#*** 75 in CSE 330S&lt;br /&gt;
#*** 37 in CSE 131&lt;br /&gt;
#*** 45.5 in CSE 260M&lt;br /&gt;
&lt;br /&gt;
=== Querying Your Database ===&lt;br /&gt;
&lt;br /&gt;
Now that you have a fully-functional, populated database, let's do some queries on it!&lt;br /&gt;
&lt;br /&gt;
Please Running the following &amp;lt;code&amp;gt;SELECT&amp;lt;/code&amp;gt; queries, then copy the output to a text file of the form &amp;lt;code&amp;gt;query1.txt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;query2.txt&amp;lt;/code&amp;gt;, and so on, and commit them with the rest of your repository (be sure to include your query command and the entire response, including the number of results found). For each query, only the requested columns should be present. You will receive 0 points for any query that includes additional columns.&lt;br /&gt;
&lt;br /&gt;
# Select the entire grades table.&lt;br /&gt;
# Select all fields describing the courses offered in the College of Arts &amp;amp; Sciences (school code &amp;lt;code&amp;gt;L&amp;lt;/code&amp;gt;).&lt;br /&gt;
# The names, student IDs, and CSE330 grades of all students who are in CSE330S.&lt;br /&gt;
#: '''Note:''' This query should involve joins.  You don't need to use any aggregation functions.&lt;br /&gt;
# The names, e-mails, and average grades of any student with an average below 50 so that the dean can send them an email notification that they are now on academic probation.&lt;br /&gt;
#: ''You should be able to do this in only one query, without making any temporary tables.  You will need to use aggregation functions and the &amp;lt;code&amp;gt;HAVING&amp;lt;/code&amp;gt; keyword.''&lt;br /&gt;
# An individual report card for Jack Johnson, consisting of only his student ID, e-mail address, and average grade.&lt;br /&gt;
#: ''Again, you should be able to do this in just one query, using the correct combination of aggregation functions and joins.''&lt;br /&gt;
#: '''Note:''' Your query must look for students with the name &amp;quot;Jack Johnson&amp;quot; instead of hard-coding the student ID.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs on this project.  You may work with the same partner from Module 2, or change to someone else.&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your Git repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple News Web Site ===&lt;br /&gt;
&lt;br /&gt;
'''Examples:'''&lt;br /&gt;
* http://digg.com/&lt;br /&gt;
* http://slashdot.org/&lt;br /&gt;
* https://news.ycombinator.com/&lt;br /&gt;
&lt;br /&gt;
You should use '''PHP''' unless you get permission to use another web technology from the instructor.  You may also use phpMyAdmin to help set up databases.&lt;br /&gt;
&lt;br /&gt;
You may find this wiki article helpful: [[PHP and MySQL]]&lt;br /&gt;
&lt;br /&gt;
==== Requirements ====&lt;br /&gt;
&lt;br /&gt;
* Users can register for accounts and then log in to the website.&lt;br /&gt;
* Accounts should have both a username and a ''secure'' password.  '''NEVER store plaintext passwords in a database!'''&lt;br /&gt;
*: For more information on password security, refer to [[Web Application Security, Part 2#Password Security|the Web Application Security guide]].&lt;br /&gt;
* Registered users can submit story commentary.&lt;br /&gt;
*: A link can be associated with each story, and they should be stored in a separate database field from the story.&lt;br /&gt;
*: For example, a story that included a link could look like the following:&lt;br /&gt;
*:: Title: Check out this cool search engine I found!&lt;br /&gt;
*:: Body: This search engine that I found has been very helpful with all of my homework assignments. Searching my error messages helps me debug.&lt;br /&gt;
*:: Link: http://google.com&lt;br /&gt;
* Registered users can comment on any story.&lt;br /&gt;
* Unregistered users can only view stories and comments.&lt;br /&gt;
* Registered users can edit and delete their stories and comments.&lt;br /&gt;
* All data must be kept in a MySQL database (user information, stories, comments, and links).&lt;br /&gt;
* Creative Portion.&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
No application is finished until much thought is put into web security and best practice.  Throughout this course, we heavily emphasize the dogma of [https://mirrors.meiert.org/coderesponsibly.org/ responsible] coding.&lt;br /&gt;
&lt;br /&gt;
Read this week's Web Application Security guide: [[Web Application Security, Part 2]].  In particular, your project needs to:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to be secure against SQL injection attacks'''. If you are using prepared queries, you should already be safe on this front.&lt;br /&gt;
* '''Your passwords need to be securely hashed salted''' to prevent rainbow table attacks.&lt;br /&gt;
* '''You should pass tokens in forms''' to prevent CSRF attacks.&lt;br /&gt;
* '''You should check all preconditions on the server side''' to prevent Abuse of Functionality attacks.&lt;br /&gt;
&lt;br /&gt;
You shouldn't forget the practices you learned last week:&lt;br /&gt;
&lt;br /&gt;
* '''Your page should validate''' with no errors or warnings through the W3C validator.&lt;br /&gt;
* '''Filter Input and Escape Output''', but not the other way around.&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
We will be grading the following aspects of your work.  There are 100 points total.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Assignments (including code) must be committed to Github by the end of class on the due date (commit early and often). Failing to commit by the end of class on the due date will result in a 0. ''' &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''If you do not include a link to your group portion running on your instance in your group portion README.md, you will receive a 0 for the group portion.''' &lt;br /&gt;
________&lt;br /&gt;
&lt;br /&gt;
# '''MySQL Queries (25 Points):'''&lt;br /&gt;
#* A MySQL server is running on your instance. Put a screenshot in your repository of your terminal connected to your MySQL server. ( (2 points)&lt;br /&gt;
#* Tables' fields, including data types and foreign keys, are correct (8 points)&lt;br /&gt;
#*: ''Note: To demonstrate the structure of your tables, you should commit a text file containing the output of the &amp;lt;code&amp;gt;SHOW CREATE TABLE&amp;lt;/code&amp;gt; command '''for each table.''' Each table's file should have a name of the form &amp;lt;code&amp;gt;tablename.sql&amp;lt;/code&amp;gt; (e.g. &amp;lt;code&amp;gt;students.sql&amp;lt;/code&amp;gt;).''&lt;br /&gt;
#* The output of each of the five queries is correct. (3 points each)&lt;br /&gt;
#*: ''Note: To demonstrate the output of your queries, text files containing the 'entire' result (including the query and number of records found) of running each query should committed to Github. The file for query 1 should be named &amp;lt;code&amp;gt;query1.txt&amp;lt;/code&amp;gt;, the file for query 2 should be named &amp;lt;code&amp;gt;query2.txt&amp;lt;/code&amp;gt;, and so on.''&lt;br /&gt;
# '''News Site (60 Points):'''&lt;br /&gt;
#* '''''User Management (20 Points):'''''&lt;br /&gt;
#** A session is created when a user logs in (3 points)&lt;br /&gt;
#** New users can register (3 points)&lt;br /&gt;
#** Passwords are hashed, salted, and checked securely (3 points)&lt;br /&gt;
#**: ''Note: You will receive 0 points for this section if you use the &amp;lt;code&amp;gt;==&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;===&amp;lt;/code&amp;gt; operators to compare password hashes, or if you use the &amp;lt;code&amp;gt;crypt&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;md5&amp;lt;/code&amp;gt; functions at any point.''&lt;br /&gt;
#** Users can log out (3 points)&lt;br /&gt;
#** A user can edit and delete his/her own stories and comments but cannot edit or delete the stories or comments of another user (8 points)&lt;br /&gt;
#* '''''Story and Comment Management (20 Points):'''''&lt;br /&gt;
#** Relational database is configured with correct data types and foreign keys (4 points)&lt;br /&gt;
#*: ''Note: To demonstrate the structure of your database, you should commit a 'single' text file containing the output of the &amp;lt;code&amp;gt;SHOW CREATE TABLE&amp;lt;/code&amp;gt; command '''for all tables in your database,''' called &amp;lt;code&amp;gt;tables.sql&amp;lt;/code&amp;gt;. This one file should contain the output for all of your tables.&lt;br /&gt;
#** Stories can be posted (3 points)&lt;br /&gt;
#** A link can be associated with each story, and is stored in a separate database field from the story (3 points)&lt;br /&gt;
#** Comments can be posted in association with a story (4 points)&lt;br /&gt;
#** Stories can be edited and deleted (3 points)&lt;br /&gt;
#** Comments can be edited and deleted (3 points)&lt;br /&gt;
#**: ''Note: Although there are only 6 points allocated for editing/deleting in this section, there are 8 more points at stake in the User Management section that cannot be earned unless editing/deleting is implemented.  Implementing editing but not deleting, or vice-versa, will result in earning half the points.''&lt;br /&gt;
#* '''''Best Practices (15 Points):'''''&lt;br /&gt;
#** Code is well formatted and easy to read, with proper commenting (3 points)&lt;br /&gt;
#** Safe from SQL Injection attacks (2 points)&lt;br /&gt;
#** Site follows the FIEO philosophy (3 points)&lt;br /&gt;
#** All pages pass the W3C HTML and CSS validators (2 points)&lt;br /&gt;
#** CSRF tokens are passed when creating, editing, and deleting comments and stories (5 points)&lt;br /&gt;
#* '''''Usability (5 Points):'''''&lt;br /&gt;
#** Site is intuitive to use and navigate (4 points)&lt;br /&gt;
#** Site is visually appealing (1 point)&lt;br /&gt;
# '''Creative Portion (15 Points)''' (see below)&lt;br /&gt;
#* '''''Make sure you have a README.md file in your group repo with the following:'''''&lt;br /&gt;
#** Names and Student IDs of all the group members&lt;br /&gt;
#** A link to your homepage of the site&lt;br /&gt;
#** A brief description of what you did for your creative portion&lt;br /&gt;
#** Any additional login details needed for the TA&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Module_2&amp;diff=2859</id>
		<title>Module 2</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Module_2&amp;diff=2859"/>
		<updated>2023-01-10T19:29:02Z</updated>

		<summary type="html">&lt;p&gt;Zach: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__ &lt;br /&gt;
Module 2 introduces you to Linux, a command-line environment, the Apache web server, and PHP.  You will create and configure your own cloud instance, install Apache and related software, and then form groups to make a simple file sharing site.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:1.3em; line-height:1.2em; color:blue;&amp;quot;&amp;gt;'''DO NOT WAIT UNTIL THE LAST MINUTE TO START ON THIS (or any) MODULE!'''  The most common reason students perform poorly in this class is procrastination.  You have been warned.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using the Wiki ==&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
Text enclosed by &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;&amp;lt;&amp;lt;/syntaxhighlight&amp;gt; and &amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; inline&amp;gt;&amp;gt;&amp;lt;/syntaxhighlight&amp;gt; should be replaced by content unique to you.&lt;br /&gt;
&lt;br /&gt;
'''Example'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo useradd -r -m -c &amp;quot;&amp;lt;My Full Name&amp;gt;&amp;quot; &amp;lt;usernameHere&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
becomes&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ sudo useradd -r -m -c &amp;quot;Zach Cohn&amp;quot; zcohn&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
== Reading ==&lt;br /&gt;
&lt;br /&gt;
The following articles on the online class wiki textbook contain information that will help you complete the assignments.&lt;br /&gt;
&lt;br /&gt;
* [[Linux]]&lt;br /&gt;
* [[Bash]]&lt;br /&gt;
* [[Amazon Web Services]]&lt;br /&gt;
* [[SSH]]&lt;br /&gt;
* [[Apache]]&lt;br /&gt;
* [[PHP]]&lt;br /&gt;
* [[Workflow]]&lt;br /&gt;
* [[VS Code]]&lt;br /&gt;
* [[Web Application Security, Part 1]]&lt;br /&gt;
* [[FAQ - Mod 2]]&lt;br /&gt;
&lt;br /&gt;
== Individual Assignments ==&lt;br /&gt;
&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;There are a lot of wiki pages that you need to read in order to complete the individual portion of Module 2.  The wiki pages contain an assortment of required steps, optional steps, and information.  To make things easier, we have highlighted the ''required steps'' with a red bar, like you see on the left of this message.  Do not skip anything marked with a red bar, or else you will not have a perfectly configured instance.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== Learn About Linux ===&lt;br /&gt;
&lt;br /&gt;
Linux is an open-source operating system based on UNIX. Linux is highly versatile and is used in a wide range of applications.&lt;br /&gt;
&lt;br /&gt;
If you are not a Linux guru, read the Linux guide to get started: [[Linux]]&lt;br /&gt;
&lt;br /&gt;
=== Windows Users Only: Enable Windows Subsystem for Linux (WSL) or Install Cygwin ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You will need WSL or Cygwin in order to log into and configure your EC2 instance. Cygwin is already installed on the CEC machines. If you're using Windows 10, you can use WSL, which is an officially-supported way of accessing a Linux terminal on Windows. If not, you'll have to use Cygwin. Instructions for installing either on your personal machine are located in [[Workflow#Cygwin|the Workflow guide]].&lt;br /&gt;
&lt;br /&gt;
Mac OS X users should located the &amp;quot;Terminal&amp;quot; application, which is installed by default; you will need this in the coming steps.&lt;br /&gt;
&lt;br /&gt;
=== Create an AWS EC2 Instance ===&lt;br /&gt;
&lt;br /&gt;
Once you understand [[Linux]], you need to set up your Amazon EC2 Instance.  Use the AWS article to guide you through the process: [[Amazon Web Services]]&lt;br /&gt;
&lt;br /&gt;
=== Configure SSH ===&lt;br /&gt;
&lt;br /&gt;
Follow the instructions in [[SSH#SSH Configuration|the SSH guide]] to do the following:&lt;br /&gt;
&lt;br /&gt;
# Create your own SSH key pair&lt;br /&gt;
# Log in as the default user to your EC2 instance&lt;br /&gt;
# Create a new user&lt;br /&gt;
# Give the new user your SSH public key&lt;br /&gt;
&lt;br /&gt;
From now on, when you need to log into your EC2 instance as an administrator, just pop up a terminal and run:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ ssh &amp;lt;your-instance-username&amp;gt;@&amp;lt;ec2-xx-xx-xx-xx.compute-1.amazonaws.com&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To save from typing this command in every time you want to access your server, you can set an '''alias''' in your terminal.&lt;br /&gt;
&lt;br /&gt;
In the '''Mac''' terminal, vim ~/.zshrc and input the following command:&lt;br /&gt;
 $ alias aws='ssh &amp;lt;your-instance-username&amp;gt;@&amp;lt;ec2-xx-xx-xx-xx.compute-1.amazonaws.com&amp;gt;'&lt;br /&gt;
Now, whenever you type aws in your terminal, it will type your ssh command.&lt;br /&gt;
&lt;br /&gt;
In '''Cygwin''', vim ~/.bash_profile and input the following:&lt;br /&gt;
 export aws=&amp;quot;ssh &amp;lt;your-instance-username&amp;gt;@&amp;lt;ec2-xx-xx-xx-xx.compute-1.amazonaws.com&amp;gt;&amp;quot;&lt;br /&gt;
And you run this command by typing '''$aws'''&lt;br /&gt;
Also note that you may have to restart your terminal for this to take effect, or put the command in your ~/.bashrc file&lt;br /&gt;
&lt;br /&gt;
=== Install Essential Packages ===&lt;br /&gt;
&lt;br /&gt;
Recall that software installation in Linux instances is usually handled through a package manager, like '''yum'''.  For more information, refer to [[Linux#Repository-Based Package Managers|the Linux guide]].&lt;br /&gt;
&lt;br /&gt;
To make sure everything is working properly, '''install your first package(s) according to the ''Essential Packages'' subsection in the Linux guide.'''&lt;br /&gt;
&lt;br /&gt;
=== Set the Timezone ===&lt;br /&gt;
&lt;br /&gt;
'''Set your server to use US Central time (America/Chicago).'''  Instructions are in the Linux guide: [[Linux#Synchronizing Date and Time]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up the Apache Web Server ===&lt;br /&gt;
&lt;br /&gt;
You need to '''install the Apache web server on your EC2 instance'''.  Refer to [[Apache|the Apache guide]].&lt;br /&gt;
&lt;br /&gt;
In order for your web server to be accessible, you need to '''open up Port 80 on your EC2 instance'''.  Instructions are in the AWS guide: [[Amazon Web Services#Enabling Web Access to your EC2 Instance]]&lt;br /&gt;
&lt;br /&gt;
'''Enable the UserDir module in Apache.'''  Instructions are in the Apache guide: [[Apache#The UserDir Module]]&lt;br /&gt;
&lt;br /&gt;
=== Install PHP ===&lt;br /&gt;
&lt;br /&gt;
You need to '''install PHP on your EC2 server'''.  Instructions are at the top of the PHP guide: [[PHP]]&lt;br /&gt;
&lt;br /&gt;
You need to '''configure PHP to show errors'''.  Instructions are immediately below installation in the PHP guide.&lt;br /&gt;
&lt;br /&gt;
=== Learn about the PHP Language ===&lt;br /&gt;
&lt;br /&gt;
Before you can continue, you will need to make yourself acquainted with PHP language components.  Read the PHP guide for an overview: [[PHP#PHP Language Components]]&lt;br /&gt;
&lt;br /&gt;
=== Set Up your Workspace ===&lt;br /&gt;
&lt;br /&gt;
You are now ready to set up the workspace that you will be using for the rest of the semester.  Follow the instructions in [[Workflow]] to:&lt;br /&gt;
&lt;br /&gt;
# Make an account on GitHub&lt;br /&gt;
# Setup a repo using GitHub Classroom&lt;br /&gt;
# Clone your CSE 330 repo from GitHub&lt;br /&gt;
# Install a text editor such as '''VSCode''' to write your assignments with&lt;br /&gt;
# Either install an FTP client, or use SFTP through command line, to transfer files from your local machine to your instance&lt;br /&gt;
&lt;br /&gt;
=== Calculator ===&lt;br /&gt;
&lt;br /&gt;
'''Make a calculator using PHP and an HTML form.'''  The form should have two inputs.  The form should submit a GET request either back to the same page or to a different results page.  The calculator should support addition, subtraction, multiplication, and division by means of a radio button group on the page.  (Consider edge cases!)&lt;br /&gt;
&lt;br /&gt;
=== Git Tutorial ===&lt;br /&gt;
&lt;br /&gt;
Complete all of the levels of the Main and Remote sections of [https://learngitbranching.js.org/ this Git tutorial]. After you finish the tutorial, take two screenshots showing the completion of all of the levels of the Main and Remote sections. Place these two screenshots in your Module 2 Individual repo.&lt;br /&gt;
&lt;br /&gt;
== Group Project ==&lt;br /&gt;
&lt;br /&gt;
You will work in pairs (that means you and one other person) on this project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;font-size:1.3em; line-height:1.2em; color:blue;&amp;quot;&amp;gt;In this module, and all future modules, the group portion builds off of material you learn in the individual portion.  You should therefore complete the individual portions prior to working on the group portions.  (Trust us: it will make your life easier!)&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Important Reminder:''' frequently commit your work to your repository as a backup!&lt;br /&gt;
&lt;br /&gt;
=== Simple File Sharing Site ===&lt;br /&gt;
&lt;br /&gt;
You will be making a simple file sharing site that supports uploading, viewing, and deleting files associated with various users.  Details:&lt;br /&gt;
&lt;br /&gt;
* You should have a file named '''users.txt''' stored in a secure place on your filesystem.  It should have at least three usernames, with one username per line.&lt;br /&gt;
*: Passwords add an extra layer of complexity (encryption) that we will cover in Module 3.  You will not earn credit for implementing passwords as your creative portion for this module.&lt;br /&gt;
* Users of the file sharing site should be able to enter their username and then log in.&lt;br /&gt;
*: You may implement logins using session variables, or you may implement them using a GET parameter that is passed between pages.  You will need to always use sessions starting in Module 3.&lt;br /&gt;
* Users should see a list of all files associated with their username after the log in.&lt;br /&gt;
* Users should be able to view, upload, and delete files associated with their username.&lt;br /&gt;
* The URI should NOT reveal the internal file structure of your web site.&lt;br /&gt;
** Example of what not to do:  http://www.example.com/download.php?file=/home/paul/file.txt&lt;br /&gt;
** Another bad example:  http://www.example.com/~user/file.txt&lt;br /&gt;
** Good example: http://www.example.com/view.php?user=music&amp;amp;name=file.txt&lt;br /&gt;
*: In general, don't reveal any internal information about the site.&lt;br /&gt;
*: '''Food for thought:''' Given that Apache processes (with the exception of the main process) do not run as root, but rather as the user apache, how can you allow both your user account and the php scripts to read and write the &lt;br /&gt;
*:necessary files?&lt;br /&gt;
*:: ''Hint:'' You shouldn't be storing the user-uploaded files in public_html (that is only the place for your own web-page files), &lt;br /&gt;
*::''Hint number 2:''  you will need to use chown to change permissions to let user apache have permissions on the user-files (that '''are not''' in the public_html folder). If you don't know what this does or how to do this, look at the [[Apache]] page&lt;br /&gt;
* You should customize your file sharing site by implementing an additional feature or two as part of the '''creative portion'''.&lt;br /&gt;
&lt;br /&gt;
You will probably find the PHP guide on this wiki to be helpful: [[PHP#Other PHP Tips]]&lt;br /&gt;
&lt;br /&gt;
=== Web Security and Validation ===&lt;br /&gt;
&lt;br /&gt;
Your project needs to demonstrate that thought was put into web security and best practice.  For more information, see this week's Web Application Security guide: [[Web Application Security, Part 1]]&lt;br /&gt;
&lt;br /&gt;
In particular:&lt;br /&gt;
&lt;br /&gt;
* '''Your application needs to follow the conventions of FIEO (Filter Input and Escape Output)'''.  Things you should filter include file names, usernames, and so on.&lt;br /&gt;
* '''Your project must pass the W3C Validator with no errors or warnings'''.  For more information, see the HTML and CSS guide: [[HTML and CSS#Validation]]&lt;br /&gt;
&lt;br /&gt;
== Grading ==&lt;br /&gt;
&lt;br /&gt;
We will be grading the following aspects of your work.  There are 120 points total. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Assignments (including code) must be committed to GitHub by the end of class on the due date. Commit early and often. Failing to commit by the end of class on the due date will result in a 0. &lt;br /&gt;
&lt;br /&gt;
_____________&lt;br /&gt;
&lt;br /&gt;
# '''Cloud Instance and Web Server (30 Points):'''&lt;br /&gt;
#* You can SSH into your instance using your own custom username and SSH key. Put a screenshot in your repository of your terminal SSH-ing into your instance (15 points)&lt;br /&gt;
#* Your custom username is able to perform SUDO commands. Put a screenshot in your repository of you successfully executing a command with sudo (5 points)&lt;br /&gt;
#* The time zone is correct on your instance. Put a screenshot in your repository of the results of the `date` command (5 points)&lt;br /&gt;
#* The UserDir Apache module is working. Place a file in /home/&amp;lt;username&amp;gt;/public_html and link to the file in your README.md (5 points)&lt;br /&gt;
# '''PHP Calculator (15 Points):'''&lt;br /&gt;
#* The calculator is able to perform all four functions with floating point numbers (2 points each, 8 points in total)&lt;br /&gt;
#* Each function is given as a radio button choice (4 points)&lt;br /&gt;
#* The calculator page passes the W3C HTML validator (3 points)&lt;br /&gt;
#* '''''Make sure you have a README.md file in your individual repo with the link to your calculator on your instance.''''' See the Creative Portion section for more information about .md files.&lt;br /&gt;
# '''Git Tutorial (20 Points):'''&lt;br /&gt;
#* Two screenshots showing the completion of all of the levels of the Main and Remote sections placed in your individual assignment repository.&lt;br /&gt;
# '''File Sharing Site (40 Points):'''&lt;br /&gt;
#* '''''File Management (25 Points):'''''&lt;br /&gt;
#** Users should not be able to see any files until they enter a username and log in (4 points)&lt;br /&gt;
#**: ''Remember that users.txt should be stored in a secure location on your filesystem.  That is, '''you should not be able to type any URL into your browser and see the raw users.txt file!'''''&lt;br /&gt;
#** Users can see a list of all files they have uploaded (4 points)&lt;br /&gt;
#** Users can open files they have previously uploaded (5 points)&lt;br /&gt;
#**: ''Note: Users should be able to open not only plain text files but also other file formats: images, spreadsheets, etc.''&lt;br /&gt;
#** Users can upload files (4 points)&lt;br /&gt;
#**: ''Note: Like users.txt, uploaded files should be stored in a secure location on your filesystem.  That is, '''do not keep your uploads directory underneath a directory served by Apache!'''''&lt;br /&gt;
#** Users can delete files.  If a file is &amp;quot;deleted&amp;quot;, it should actually be removed from the filesystem (4 points)&lt;br /&gt;
#** The directory structure is hidden. Users should not be able to access or view files by manipulating a URL. (2 points)&lt;br /&gt;
#** Users can log out (2 points)&lt;br /&gt;
#**: ''Note: If using session variables, you must ''actually'' log out the user by destroying their session; i.e., don't just redirect them to the login screen.''&lt;br /&gt;
#* '''''Best Practices (10 Points):'''''&lt;br /&gt;
#** Code is well formatted and easy to read, with proper commenting (4 points)&lt;br /&gt;
#** The site follows the FIEO philosophy (3 points)&lt;br /&gt;
#** All pages pass the W3C validator (3 points)&lt;br /&gt;
#* '''''Usability (5 Points):'''''&lt;br /&gt;
#** Site is intuitive to use and navigate (4 points)&lt;br /&gt;
#** Site is visually appealing (1 point)&lt;br /&gt;
# '''Creative Portion (15 Points)''' (see below)&lt;br /&gt;
#* '''''Make sure you have a README.md file in your group repo with the following:'''''&lt;br /&gt;
#** An .md file is a plain text file called a markdown file  [https://guides.github.com/features/mastering-markdown/ ] .  &lt;br /&gt;
#***The contents of your README.md file are shown on your repo, making it easier for us to grade&lt;br /&gt;
#*** You may style the page with bolding, hyperlings, images, block quotes and lists&lt;br /&gt;
#*** [http://dillinger.io/ This online markdown editor] makes it easy to learn this format  &lt;br /&gt;
#** The link to your file sharing site. '''''We need this to grade your work.'''''&lt;br /&gt;
#** A brief description of what you did for your creative portion&lt;br /&gt;
#** Any additional login details needed for the TA&lt;br /&gt;
&lt;br /&gt;
=== Creative Portion ===&lt;br /&gt;
&lt;br /&gt;
This module and all future modules will require that you invest some time into creating additional features for your group project.  Plan to invest at the very least 60 minutes of your time into the creative portion.  In the above rubric, viewing files is worth five and uploading is worth four. The creative portion is worth fifteen points; it should be a very sizable part of your project.&lt;br /&gt;
&lt;br /&gt;
* The creative portion is an opportunity for you to learn the material of your own interest.&lt;br /&gt;
* You will not earn credit for a creative-portion feature that simply rehashes something you've already done in a previous module.&lt;br /&gt;
&lt;br /&gt;
If you need ideas for a creative portion, or if you want to know whether or not your creative portion idea is &amp;quot;hard enough&amp;quot;, ask a TA.&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 2]]&lt;br /&gt;
[[Category:Modules]]&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=VS_Code&amp;diff=2858</id>
		<title>VS Code</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=VS_Code&amp;diff=2858"/>
		<updated>2023-01-10T06:33:59Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* SFTP Integration (Shipping files to your server) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Getting Started With Each Module ==&lt;br /&gt;
&lt;br /&gt;
* Create Github repo using the CSE 330 repo creator  (Check Piazza for the link)&lt;br /&gt;
* Navigate to the created repo in Github&lt;br /&gt;
* Clone the repo via https to a dedicated folder on your computer&lt;br /&gt;
&lt;br /&gt;
[[File:File-Structure.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* In VS Code, File &amp;gt; Open the Spring2019-module1-individual-STUDENTID '''folder''' that you cloned to your computer&lt;br /&gt;
&lt;br /&gt;
If you followed the above steps correctly, the folder's Git should be configured to your Github repository!  I highly recommend creating your Github repo, cloning the folder to a designated spot, and keeping all modules separated for the semester as shown in the image above.&lt;br /&gt;
&lt;br /&gt;
== Module 1 -- Using the Git Integration ==&lt;br /&gt;
'''Note: If you're using Windows, you may need to install Git on your machine first. https://git-scm.com/download/win . You can check if you have Git running by typing git --version in your terminal'''&lt;br /&gt;
&lt;br /&gt;
* First, open the File Explorer tab on the left, and right click to create a new file, birthday.html&lt;br /&gt;
[[File:New-file.png|400px|center]]&lt;br /&gt;
* Ensure VS Code has it marked as an html file (see the file type next to the smiley face)&lt;br /&gt;
* Type '''doc''' followed by enter, and allow VS Code to generate a basic HTML file for you (use VS Code to your advantage! It can do a lot of your coding for you).&lt;br /&gt;
* Save the file, you should see a popup next to the Version Control symbol on the left. VS Code has detected that your project is different than what it is in your remote Github repo.&lt;br /&gt;
* To commit, simply type a message in the box and click the check mark above it.  To push to your Github repo, click the 3 dots next to the check mark and select 'push'&lt;br /&gt;
* Note this is also where you can pull from your remote.&lt;br /&gt;
&lt;br /&gt;
==== Bonus - Module 1 ====&lt;br /&gt;
* If you like your text editor to look pretty, you can go to the Extensions tab and search for different themes. (Check out the Material theme!)&lt;br /&gt;
* You can view your settings by clicking CMD + , (Mac) or Ctrl + , (Windows).  Search for Theme and choose one that works for you!&lt;br /&gt;
&lt;br /&gt;
== Module 2 == &lt;br /&gt;
=== DISCLAIMER ===&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;There are two SFTP VSCode extensions of the same name. One of them is depreciated. Use the extension distributed by Natizyskunk.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== SFTP Integration (Shipping files to your server) ===&lt;br /&gt;
# Select a folder to use for your work and open it in VSCode. When editing files on your instance, the file will be saved locally in this location for editing and reuploaded&lt;br /&gt;
# Open the Extensions tab and search for 'SFTP'. Download the version distributed by &amp;quot;Natizyskunk&amp;quot;.&lt;br /&gt;
# To use commands in VS Code, type '''Cmd + Shift + P''' (Mac), or '''Ctrl + Shift + P''' on windows. &lt;br /&gt;
# Type SFTP and open the sftp config command. &lt;br /&gt;
&lt;br /&gt;
Your config.json file should look like the following:&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;name&amp;quot;: &amp;quot;&amp;lt;My Instance&amp;gt;&amp;quot;,&lt;br /&gt;
    &amp;quot;host&amp;quot;: &amp;quot;&amp;lt;ec2-xxxxx-xxxxxx-xxxxx.amazonaws.com&amp;gt;&amp;quot;,&lt;br /&gt;
    &amp;quot;protocol&amp;quot;: &amp;quot;sftp&amp;quot;,&lt;br /&gt;
    &amp;quot;port&amp;quot;: 22,&lt;br /&gt;
    &amp;quot;username&amp;quot;: &amp;quot;&amp;lt;custom instance username&amp;gt;&amp;quot;&lt;br /&gt;
    &amp;quot;remotePath: &amp;quot;/home/&amp;lt;custom instance username&amp;gt;/&amp;quot;,&lt;br /&gt;
    &amp;quot;uploadOnSave&amp;quot;: true,&lt;br /&gt;
    &amp;quot;privateKeyPath&amp;quot;: &amp;quot;&amp;lt;/path/to/.ssh/id_rsa&amp;gt;&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
- Note the uploadOnSave field is optional, but can be nice!&lt;br /&gt;
- Check the VS Code output for errors in your config.&lt;br /&gt;
&lt;br /&gt;
Additionally: You should notice an SFTP tab on the side of VS Code. Here, you can view the file structure on your server.]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Preventing &amp;quot;Edit in Local&amp;quot; when editing files'''&lt;br /&gt;
&lt;br /&gt;
In order to edit locally, you'll have to right click on the file you wish to edit and select &amp;quot;Edit in local&amp;quot; every time. To avoid this, you can:&lt;br /&gt;
# Open vscode settings by File &amp;gt;&amp;gt; Preferences &amp;gt;&amp;gt; Settings&lt;br /&gt;
# In settings, search for &amp;quot;downloadWhenOpenInRemoteExplorer&amp;quot; and toggle it on&lt;br /&gt;
# restart VScode.&lt;br /&gt;
&lt;br /&gt;
=== Testing Everything Locally ===&lt;br /&gt;
If you would like to avoid having to frequently upload your changes to your instance in order to test your changes, you can optionally set up a local PHP server.&lt;br /&gt;
&lt;br /&gt;
'''To run PHP locally'''&lt;br /&gt;
&lt;br /&gt;
'''Windows'''&lt;br /&gt;
# Download WAMP http://www.wampserver.com/en/download-wampserver-64bits/&lt;br /&gt;
# Place your project repositories in Wamp's www/ directory, and navigate to http://localhost in your browser.  You should see your projects listed here, run php files, and use phpmyadmin.&lt;br /&gt;
&lt;br /&gt;
'''Mac'''&lt;br /&gt;
# Download Homebrew. Homebrew is a great package manager for OSx and we will be using it in future modules. &lt;br /&gt;
# Type the following in your terminal and follow instructions&lt;br /&gt;
 /usr/bin/ruby -e &amp;quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&amp;quot;&lt;br /&gt;
# In your terminal, type '''php -v'''. If your version is less than 7, update with brew. '''brew install php'''&lt;br /&gt;
# In VS Code, search for the extension '''Php Server'''. After installing, use VS Code's command pallette with CMD+Shift+P , search for PHP, and select start server.  You should be able to view your project in your localhost&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=VS_Code&amp;diff=2857</id>
		<title>VS Code</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=VS_Code&amp;diff=2857"/>
		<updated>2023-01-10T06:33:36Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* SFTP Integration (Shipping files to your server) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Getting Started With Each Module ==&lt;br /&gt;
&lt;br /&gt;
* Create Github repo using the CSE 330 repo creator  (Check Piazza for the link)&lt;br /&gt;
* Navigate to the created repo in Github&lt;br /&gt;
* Clone the repo via https to a dedicated folder on your computer&lt;br /&gt;
&lt;br /&gt;
[[File:File-Structure.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* In VS Code, File &amp;gt; Open the Spring2019-module1-individual-STUDENTID '''folder''' that you cloned to your computer&lt;br /&gt;
&lt;br /&gt;
If you followed the above steps correctly, the folder's Git should be configured to your Github repository!  I highly recommend creating your Github repo, cloning the folder to a designated spot, and keeping all modules separated for the semester as shown in the image above.&lt;br /&gt;
&lt;br /&gt;
== Module 1 -- Using the Git Integration ==&lt;br /&gt;
'''Note: If you're using Windows, you may need to install Git on your machine first. https://git-scm.com/download/win . You can check if you have Git running by typing git --version in your terminal'''&lt;br /&gt;
&lt;br /&gt;
* First, open the File Explorer tab on the left, and right click to create a new file, birthday.html&lt;br /&gt;
[[File:New-file.png|400px|center]]&lt;br /&gt;
* Ensure VS Code has it marked as an html file (see the file type next to the smiley face)&lt;br /&gt;
* Type '''doc''' followed by enter, and allow VS Code to generate a basic HTML file for you (use VS Code to your advantage! It can do a lot of your coding for you).&lt;br /&gt;
* Save the file, you should see a popup next to the Version Control symbol on the left. VS Code has detected that your project is different than what it is in your remote Github repo.&lt;br /&gt;
* To commit, simply type a message in the box and click the check mark above it.  To push to your Github repo, click the 3 dots next to the check mark and select 'push'&lt;br /&gt;
* Note this is also where you can pull from your remote.&lt;br /&gt;
&lt;br /&gt;
==== Bonus - Module 1 ====&lt;br /&gt;
* If you like your text editor to look pretty, you can go to the Extensions tab and search for different themes. (Check out the Material theme!)&lt;br /&gt;
* You can view your settings by clicking CMD + , (Mac) or Ctrl + , (Windows).  Search for Theme and choose one that works for you!&lt;br /&gt;
&lt;br /&gt;
== Module 2 == &lt;br /&gt;
=== DISCLAIMER ===&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;There are two SFTP VSCode extensions of the same name. One of them is depreciated. Use the extension distributed by Natizyskunk.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== SFTP Integration (Shipping files to your server) ===&lt;br /&gt;
# Select a folder to use for your work and open it in VSCode. When editing files on your instance, the file will be saved locally in this location for editing and reuploaded&lt;br /&gt;
# Open the Extensions tab and search for 'SFTP'. Download the version distributed by &amp;quot;Natizyskunk&amp;quot;.&lt;br /&gt;
# To use commands in VS Code, type '''Cmd + Shift + P''' (Mac), or '''Ctrl + Shift + P''' on windows. &lt;br /&gt;
# Type SFTP and open the sftp config command. &lt;br /&gt;
&lt;br /&gt;
Your config.json file should look like the following:&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;name&amp;quot;: &amp;quot;&amp;lt;My Instance&amp;gt;&amp;quot;,&lt;br /&gt;
    &amp;quot;host&amp;quot;: &amp;quot;&amp;lt;ec2-xxxxx-xxxxxx-xxxxx.amazonaws.com&amp;gt;&amp;quot;,&lt;br /&gt;
    &amp;quot;protocol&amp;quot;: &amp;quot;sftp&amp;quot;,&lt;br /&gt;
    &amp;quot;port&amp;quot;: 22,&lt;br /&gt;
    &amp;quot;username&amp;quot;: &amp;quot;&amp;lt;custom instance username&amp;gt;&amp;quot;&lt;br /&gt;
    &amp;quot;remotePath: &amp;quot;/home/&amp;lt;custom instance username&amp;gt;/&amp;quot;,&lt;br /&gt;
    &amp;quot;uploadOnSave&amp;quot;: true,&lt;br /&gt;
    &amp;quot;privateKeyPath&amp;quot;: &amp;quot;&amp;lt;/path/to/.ssh/id_rsa&amp;gt;&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
- Note the uploadOnSave field is optional, but can be nice!&lt;br /&gt;
- Check the VS Code output for errors in your config.&lt;br /&gt;
&lt;br /&gt;
Additionally: You should notice an SFTP tab on the side of VS Code. Here, you can view the file structure on your server.]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Preventing &amp;quot;Edit in Local&amp;quot; when editing files'''&lt;br /&gt;
In order to edit locally, you'll have to right click on the file you wish to edit and select &amp;quot;Edit in local&amp;quot; every time. To avoid this, you can:&lt;br /&gt;
# Open vscode settings by File &amp;gt;&amp;gt; Preferences &amp;gt;&amp;gt; Settings&lt;br /&gt;
# In settings, search for &amp;quot;downloadWhenOpenInRemoteExplorer&amp;quot; and toggle it on&lt;br /&gt;
# restart VScode.&lt;br /&gt;
&lt;br /&gt;
=== Testing Everything Locally ===&lt;br /&gt;
If you would like to avoid having to frequently upload your changes to your instance in order to test your changes, you can optionally set up a local PHP server.&lt;br /&gt;
&lt;br /&gt;
'''To run PHP locally'''&lt;br /&gt;
&lt;br /&gt;
'''Windows'''&lt;br /&gt;
# Download WAMP http://www.wampserver.com/en/download-wampserver-64bits/&lt;br /&gt;
# Place your project repositories in Wamp's www/ directory, and navigate to http://localhost in your browser.  You should see your projects listed here, run php files, and use phpmyadmin.&lt;br /&gt;
&lt;br /&gt;
'''Mac'''&lt;br /&gt;
# Download Homebrew. Homebrew is a great package manager for OSx and we will be using it in future modules. &lt;br /&gt;
# Type the following in your terminal and follow instructions&lt;br /&gt;
 /usr/bin/ruby -e &amp;quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&amp;quot;&lt;br /&gt;
# In your terminal, type '''php -v'''. If your version is less than 7, update with brew. '''brew install php'''&lt;br /&gt;
# In VS Code, search for the extension '''Php Server'''. After installing, use VS Code's command pallette with CMD+Shift+P , search for PHP, and select start server.  You should be able to view your project in your localhost&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=VS_Code&amp;diff=2856</id>
		<title>VS Code</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=VS_Code&amp;diff=2856"/>
		<updated>2023-01-10T06:32:31Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* SFTP Integration (Shipping files to your server) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Getting Started With Each Module ==&lt;br /&gt;
&lt;br /&gt;
* Create Github repo using the CSE 330 repo creator  (Check Piazza for the link)&lt;br /&gt;
* Navigate to the created repo in Github&lt;br /&gt;
* Clone the repo via https to a dedicated folder on your computer&lt;br /&gt;
&lt;br /&gt;
[[File:File-Structure.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* In VS Code, File &amp;gt; Open the Spring2019-module1-individual-STUDENTID '''folder''' that you cloned to your computer&lt;br /&gt;
&lt;br /&gt;
If you followed the above steps correctly, the folder's Git should be configured to your Github repository!  I highly recommend creating your Github repo, cloning the folder to a designated spot, and keeping all modules separated for the semester as shown in the image above.&lt;br /&gt;
&lt;br /&gt;
== Module 1 -- Using the Git Integration ==&lt;br /&gt;
'''Note: If you're using Windows, you may need to install Git on your machine first. https://git-scm.com/download/win . You can check if you have Git running by typing git --version in your terminal'''&lt;br /&gt;
&lt;br /&gt;
* First, open the File Explorer tab on the left, and right click to create a new file, birthday.html&lt;br /&gt;
[[File:New-file.png|400px|center]]&lt;br /&gt;
* Ensure VS Code has it marked as an html file (see the file type next to the smiley face)&lt;br /&gt;
* Type '''doc''' followed by enter, and allow VS Code to generate a basic HTML file for you (use VS Code to your advantage! It can do a lot of your coding for you).&lt;br /&gt;
* Save the file, you should see a popup next to the Version Control symbol on the left. VS Code has detected that your project is different than what it is in your remote Github repo.&lt;br /&gt;
* To commit, simply type a message in the box and click the check mark above it.  To push to your Github repo, click the 3 dots next to the check mark and select 'push'&lt;br /&gt;
* Note this is also where you can pull from your remote.&lt;br /&gt;
&lt;br /&gt;
==== Bonus - Module 1 ====&lt;br /&gt;
* If you like your text editor to look pretty, you can go to the Extensions tab and search for different themes. (Check out the Material theme!)&lt;br /&gt;
* You can view your settings by clicking CMD + , (Mac) or Ctrl + , (Windows).  Search for Theme and choose one that works for you!&lt;br /&gt;
&lt;br /&gt;
== Module 2 == &lt;br /&gt;
=== DISCLAIMER ===&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;There are two SFTP VSCode extensions of the same name. One of them is depreciated. Use the extension distributed by Natizyskunk.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== SFTP Integration (Shipping files to your server) ===&lt;br /&gt;
# Select a folder to use for your work and open it in VSCode. When editing files on your instance, the file will be saved locally in this location for editing and reuploaded&lt;br /&gt;
# Open the Extensions tab and search for 'SFTP'. Download the version distributed by &amp;quot;Natizyskunk&amp;quot;.&lt;br /&gt;
# To use commands in VS Code, type '''Cmd + Shift + P''' (Mac), or '''Ctrl + Shift + P''' on windows. &lt;br /&gt;
# Type SFTP and open the sftp config command. &lt;br /&gt;
&lt;br /&gt;
Your config.json file should look like the following:&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;name&amp;quot;: &amp;quot;&amp;lt;My Instance&amp;gt;&amp;quot;,&lt;br /&gt;
    &amp;quot;host&amp;quot;: &amp;quot;&amp;lt;ec2-xxxxx-xxxxxx-xxxxx.amazonaws.com&amp;gt;&amp;quot;,&lt;br /&gt;
    &amp;quot;protocol&amp;quot;: &amp;quot;sftp&amp;quot;,&lt;br /&gt;
    &amp;quot;port&amp;quot;: 22,&lt;br /&gt;
    &amp;quot;username&amp;quot;: &amp;quot;&amp;lt;custom instance username&amp;gt;&amp;quot;&lt;br /&gt;
    &amp;quot;remotePath: &amp;quot;/home/&amp;lt;custom instance username&amp;gt;/&amp;quot;,&lt;br /&gt;
    &amp;quot;uploadOnSave&amp;quot;: true,&lt;br /&gt;
    &amp;quot;privateKeyPath&amp;quot;: &amp;quot;&amp;lt;/path/to/.ssh/id_rsa&amp;gt;&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
- Note the uploadOnSave field is optional, but can be nice!&lt;br /&gt;
- Check the VS Code output for errors in your config.&lt;br /&gt;
&lt;br /&gt;
Additionally: You should notice an SFTP tab on the side of VS Code. Here, you can view the file structure on your server.]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to edit locally, you'll have to right click on the file you wish to edit and select &amp;quot;Edit in local&amp;quot; every time. To avoid this, you can:&lt;br /&gt;
# Open vscode settings by File &amp;gt;&amp;gt; Preferences &amp;gt;&amp;gt; Settings&lt;br /&gt;
# In settings, search for &amp;quot;downloadWhenOpenInRemoteExplorer&amp;quot; and toggle it on&lt;br /&gt;
# restart VScode.&lt;br /&gt;
&lt;br /&gt;
=== Testing Everything Locally ===&lt;br /&gt;
If you would like to avoid having to frequently upload your changes to your instance in order to test your changes, you can optionally set up a local PHP server.&lt;br /&gt;
&lt;br /&gt;
'''To run PHP locally'''&lt;br /&gt;
&lt;br /&gt;
'''Windows'''&lt;br /&gt;
# Download WAMP http://www.wampserver.com/en/download-wampserver-64bits/&lt;br /&gt;
# Place your project repositories in Wamp's www/ directory, and navigate to http://localhost in your browser.  You should see your projects listed here, run php files, and use phpmyadmin.&lt;br /&gt;
&lt;br /&gt;
'''Mac'''&lt;br /&gt;
# Download Homebrew. Homebrew is a great package manager for OSx and we will be using it in future modules. &lt;br /&gt;
# Type the following in your terminal and follow instructions&lt;br /&gt;
 /usr/bin/ruby -e &amp;quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&amp;quot;&lt;br /&gt;
# In your terminal, type '''php -v'''. If your version is less than 7, update with brew. '''brew install php'''&lt;br /&gt;
# In VS Code, search for the extension '''Php Server'''. After installing, use VS Code's command pallette with CMD+Shift+P , search for PHP, and select start server.  You should be able to view your project in your localhost&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=VS_Code&amp;diff=2855</id>
		<title>VS Code</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=VS_Code&amp;diff=2855"/>
		<updated>2023-01-10T06:20:17Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* DISCLAIMER */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Getting Started With Each Module ==&lt;br /&gt;
&lt;br /&gt;
* Create Github repo using the CSE 330 repo creator  (Check Piazza for the link)&lt;br /&gt;
* Navigate to the created repo in Github&lt;br /&gt;
* Clone the repo via https to a dedicated folder on your computer&lt;br /&gt;
&lt;br /&gt;
[[File:File-Structure.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
* In VS Code, File &amp;gt; Open the Spring2019-module1-individual-STUDENTID '''folder''' that you cloned to your computer&lt;br /&gt;
&lt;br /&gt;
If you followed the above steps correctly, the folder's Git should be configured to your Github repository!  I highly recommend creating your Github repo, cloning the folder to a designated spot, and keeping all modules separated for the semester as shown in the image above.&lt;br /&gt;
&lt;br /&gt;
== Module 1 -- Using the Git Integration ==&lt;br /&gt;
'''Note: If you're using Windows, you may need to install Git on your machine first. https://git-scm.com/download/win . You can check if you have Git running by typing git --version in your terminal'''&lt;br /&gt;
&lt;br /&gt;
* First, open the File Explorer tab on the left, and right click to create a new file, birthday.html&lt;br /&gt;
[[File:New-file.png|400px|center]]&lt;br /&gt;
* Ensure VS Code has it marked as an html file (see the file type next to the smiley face)&lt;br /&gt;
* Type '''doc''' followed by enter, and allow VS Code to generate a basic HTML file for you (use VS Code to your advantage! It can do a lot of your coding for you).&lt;br /&gt;
* Save the file, you should see a popup next to the Version Control symbol on the left. VS Code has detected that your project is different than what it is in your remote Github repo.&lt;br /&gt;
* To commit, simply type a message in the box and click the check mark above it.  To push to your Github repo, click the 3 dots next to the check mark and select 'push'&lt;br /&gt;
* Note this is also where you can pull from your remote.&lt;br /&gt;
&lt;br /&gt;
==== Bonus - Module 1 ====&lt;br /&gt;
* If you like your text editor to look pretty, you can go to the Extensions tab and search for different themes. (Check out the Material theme!)&lt;br /&gt;
* You can view your settings by clicking CMD + , (Mac) or Ctrl + , (Windows).  Search for Theme and choose one that works for you!&lt;br /&gt;
&lt;br /&gt;
== Module 2 == &lt;br /&gt;
=== DISCLAIMER ===&lt;br /&gt;
{{RequiredInstructions|content=&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;There are two SFTP VSCode extensions of the same name. One of them is depreciated. Use the extension distributed by Natizyskunk.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=== SFTP Integration (Shipping files to your server) ===&lt;br /&gt;
# Open the Extensions tab and search for 'sftp'. Download the first one.&lt;br /&gt;
# To use commands in VS Code, type '''Cmd + Shift + P''' (Mac), or '''Ctrl + Shift + P''' on windows. &lt;br /&gt;
# Type SFTP and open the sftp config command. &lt;br /&gt;
&lt;br /&gt;
Your config.json file should look like the following:&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;protocol&amp;quot;: &amp;quot;sftp&amp;quot;,&lt;br /&gt;
    &amp;quot;host&amp;quot;: &amp;quot;YOUR.EC2.DNS&amp;quot;,&lt;br /&gt;
    &amp;quot;port&amp;quot;: 22,&lt;br /&gt;
    &amp;quot;username&amp;quot;: &amp;quot;YOUR USERNAME&amp;quot;,&lt;br /&gt;
    &amp;quot;privateKeyPath&amp;quot;: &amp;quot;/path/to/your/id_rsa&amp;quot;,&lt;br /&gt;
    &amp;quot;remotePath&amp;quot;: &amp;quot;/home/YOUR USERNAME/public_html/module2&amp;quot;,&lt;br /&gt;
    &amp;quot;uploadOnSave&amp;quot;: true&lt;br /&gt;
  }&lt;br /&gt;
- Note the uploadOnSave field is optional, but can be nice!&lt;br /&gt;
- Check the VS Code output for errors in your config.&lt;br /&gt;
&lt;br /&gt;
Additionally: You should notice an SFTP tab on the side of VS Code. Here, you can view the file structure on your server.&lt;br /&gt;
&lt;br /&gt;
=== Testing Everything Locally ===&lt;br /&gt;
If you would like to avoid having to frequently upload your changes to your instance in order to test your changes, you can optionally set up a local PHP server.&lt;br /&gt;
&lt;br /&gt;
'''To run PHP locally'''&lt;br /&gt;
&lt;br /&gt;
'''Windows'''&lt;br /&gt;
# Download WAMP http://www.wampserver.com/en/download-wampserver-64bits/&lt;br /&gt;
# Place your project repositories in Wamp's www/ directory, and navigate to http://localhost in your browser.  You should see your projects listed here, run php files, and use phpmyadmin.&lt;br /&gt;
&lt;br /&gt;
'''Mac'''&lt;br /&gt;
# Download Homebrew. Homebrew is a great package manager for OSx and we will be using it in future modules. &lt;br /&gt;
# Type the following in your terminal and follow instructions&lt;br /&gt;
 /usr/bin/ruby -e &amp;quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&amp;quot;&lt;br /&gt;
# In your terminal, type '''php -v'''. If your version is less than 7, update with brew. '''brew install php'''&lt;br /&gt;
# In VS Code, search for the extension '''Php Server'''. After installing, use VS Code's command pallette with CMD+Shift+P , search for PHP, and select start server.  You should be able to view your project in your localhost&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Python&amp;diff=2854</id>
		<title>Python</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Python&amp;diff=2854"/>
		<updated>2023-01-10T06:10:26Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Python Script Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Languages like Java and C++ have lots of rules regarding variable types, syntax, return values, and so on. These can be cumbersome when you are trying to write short, quick scripts to perform tasks. This is where a ''scripting language'' comes into play.&lt;br /&gt;
&lt;br /&gt;
'''Python''' is a language well-suited to rapid prototype development. It is generally an ''interpreted language'', which means that, generally speaking, a Python program is converted line by line into instructions for the computer to execute as the program runs, instead of having a separate compilation step beforehand {{ref|interpreted}}. The syntax is clean, and it is usually clear at first glance what is going on when you write in Python.&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
Python may already be installed on your system. To see whether or not it is, enter the command&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ python3 --version&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If it tells you a version of Python '''greater than or equal to 3.6''' then you're good to go. If not, you need to do a quick package install to get it up and running. Using yum, it's just &amp;lt;code&amp;gt;sudo yum install python36&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you'd like to be able to just type &amp;lt;code&amp;gt;python&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;python3&amp;lt;/code&amp;gt;, you can add the following line to the &amp;lt;code&amp;gt;~/.bashrc&amp;lt;/code&amp;gt; file on your instance:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias python=&amp;quot;/usr/bin/python3&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Python 2 vs Python 3 ====&lt;br /&gt;
&lt;br /&gt;
In 2008, a new version of Python – Python 3 – was released, with a number of changes that made it incompatible with the previous version, Python 2. For several years, the Python community was slow to make the change to Python 3, but today, Python 3 is ''the'' standard for new code. The ''only'' reason to write Python 2 code today is because you have to work in an environment or with libraries that do not support Python 3, and that situation is becoming increasingly rare.&lt;br /&gt;
&lt;br /&gt;
'''For CSE 330 (and this guide), you ''must'' use Python 3.6 or greater.'''&lt;br /&gt;
&lt;br /&gt;
=== Pip ===&lt;br /&gt;
&lt;br /&gt;
Linux distributions have package managers like ''Apt'', ''Yum'', and ''YaST''. PHP has a package manager named ''PEAR''. It's now time to introduce Python's leading package manager: '''pip'''.&lt;br /&gt;
&lt;br /&gt;
Once you have pip installed, you can use it to install Python packages. Use the &amp;lt;code&amp;gt;pip-3.6&amp;lt;/code&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ pip-3.6 install &amp;lt;package_name&amp;gt; # RHEL&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you'd like to be able to just type &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;pip-3.6&amp;lt;/code&amp;gt;, you can add the following line to the &amp;lt;code&amp;gt;~/.bashrc&amp;lt;/code&amp;gt; file on your instance:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias pip=&amp;quot;/usr/bin/pip-3.6&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Running Python =&lt;br /&gt;
&lt;br /&gt;
There are two common ways to run Python code: via the console, and via a Python script file.&lt;br /&gt;
&lt;br /&gt;
=== The Python Console ===&lt;br /&gt;
&lt;br /&gt;
The Python console enables you to experiment with code without opening a text editor. To enter the Python console, simply type the ''python'' command at the terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ python3&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
To leave the interactive console, either type &amp;lt;code&amp;gt;quit()&amp;lt;/code&amp;gt; or press &amp;lt;code&amp;gt;Ctrl-D&amp;lt;/code&amp;gt; (on both Mac and Windows).&lt;br /&gt;
&lt;br /&gt;
=== Python Script Files ===&lt;br /&gt;
&lt;br /&gt;
You can also save Python script files for later use. The extension for Python scripts is &amp;lt;code&amp;gt;*.py&amp;lt;/code&amp;gt;. To run a script file, simply feed its path as an argument to the &amp;lt;code&amp;gt;python&amp;lt;/code&amp;gt; command in Terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ python3 &amp;lt;my_script&amp;gt;.py&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Python Syntax and Language Components =&lt;br /&gt;
&lt;br /&gt;
This section contains a very brief overview of Python syntax. For a more comprehensive introduction, see [http://docs.python.org/tutorial/ the Python docs].&lt;br /&gt;
&lt;br /&gt;
=== Python's Type System ===&lt;br /&gt;
&lt;br /&gt;
Python is a dynamically-typed, strongly-typed, and duck-typed language. What does that mean? Well, let's take those categories one by one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
'''Dynamic typing''', in contrast to ''static typing'' means that the types of objects can be changed. In Java, for instance, if you tried to write the following code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
int c = 2;&lt;br /&gt;
c = &amp;quot;fish&amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Your code would fail to compile, because the Java compiler wouldn't allow you to change the type of the variable &amp;lt;code&amp;gt;c&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Python, however, is just fine with that. You can write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
c = 2&lt;br /&gt;
c = &amp;quot;fish&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And Python will happily do what you ask.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
'''Strong typing''', in contrast to ''weak typing'', means, roughly, that a language won't implicitly convert types for you. So far, you've used a lot of PHP, which is very weakly typed. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
echo &amp;quot;10&amp;quot; . 2;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In PHP, this works just fine. The PHP interpreter sees that &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt; is an int, and silently converts it to a string for you, so that &amp;lt;code&amp;gt;&amp;quot;10&amp;quot;. 2&amp;lt;/code&amp;gt; equals &amp;lt;code&amp;gt;&amp;quot;102&amp;quot;&amp;lt;/code&amp;gt;. The problem with weak typing is that it can make it unclear to the programmer why things are happening the way they are. For instance, in PHP, the expression &amp;lt;code&amp;gt;&amp;quot;10&amp;quot; == 10&amp;lt;/code&amp;gt; is true, which can be less than obvious. Python, however, tries to disallow that sort of thing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;quot;10&amp;quot; + &amp;quot;10&amp;quot; # Allowed – concatenates the two strings.&lt;br /&gt;
10   +  10  # Allowed – adds the two ints.&lt;br /&gt;
&amp;quot;10&amp;quot; +  10  # Not allowed – raises a TypeError&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Perhaps the one exception to this rule is the relationship between numeric types; it's perfectly fine to add a float to an int, for example.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
'''Duck-typing''' is a little bit different than the other categories, because it doesn't really have a direct opposite. Essentially, duck-typing is the philosophy that &amp;quot;If it walks like a duck, and quacks like a duck, it's a duck.&amp;quot; In programming terms, that means that we often don't care what type an object is, as long as it can do the things we ask.&lt;br /&gt;
&lt;br /&gt;
Let's look at an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# This function doubles the value it's passed.&lt;br /&gt;
def double(thing):&lt;br /&gt;
    return thing + thing&lt;br /&gt;
double(10) # Returns 20&lt;br /&gt;
double(&amp;quot;fish&amp;quot;) # Returns &amp;quot;fishfish&amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this were Java, we'd have to write two different methods here: one for things of type &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;, and one for things of type &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;. Since this is Python, though, we don't have to do that. Instead, Python lets us say, essentially: &amp;quot;This function uses the &amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt; operator, so you can pass whatever object you want to the function, as long as the function supports the &amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt; operator&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
To quote [https://groups.google.com/forum/?hl=en#!msg/comp.lang.python/CCs2oJdyuzc/NYjla5HKMOIJ Alex Martelli], one of the key people in the Python project,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;quot;[Don't] check whether it IS-a duck: check whether it QUACKS-like-a duck, WALKS-like-a duck, etc, etc, depending on exactly what subset of duck-like behaviour you need.&amp;quot;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Types ===&lt;br /&gt;
&lt;br /&gt;
In Python, the basic scalar types are:&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt; – a string.&lt;br /&gt;
# &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; – an integer object with unlimited digits.&lt;br /&gt;
# &amp;lt;code&amp;gt;bool&amp;lt;/code&amp;gt; – a Boolean value.&lt;br /&gt;
# &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt; – a floating point number; generally equivalent to &amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt; in Java.&lt;br /&gt;
# &amp;lt;code&amp;gt;bytes&amp;lt;/code&amp;gt; – represents a collection of bytes; you're unlikely to use this often.&lt;br /&gt;
&lt;br /&gt;
Casting is done in the C style - to parse an &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; from a string, for instance, you'd write &amp;lt;code&amp;gt;int(&amp;quot;123&amp;quot;)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Basic Control Flow ===&lt;br /&gt;
In Python, blocks of code are delineated using colons and indentation instead of curly braces. '''''That means that proper indentation is mandatory.''''' Every time you use a colon, you must indent one step further, and every time a block ends, you must unindent a step.&lt;br /&gt;
&lt;br /&gt;
Conditional statements are done using the &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; operators, like in the example below - pay attention to the indentation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
cookies_left = 10&lt;br /&gt;
cake_slices_left = 3&lt;br /&gt;
if cookies_left &amp;gt; 10:&lt;br /&gt;
    print(&amp;quot;Lots of cookies!&amp;quot;)&lt;br /&gt;
elif cookies_left &amp;gt; 8:&lt;br /&gt;
    print(&amp;quot;Plenty left!&amp;quot;)&lt;br /&gt;
elif cookies_left == 5:&lt;br /&gt;
    print(&amp;quot;Halfway done!&amp;quot;)&lt;br /&gt;
else:&lt;br /&gt;
    if cake_slices_left == 3:&lt;br /&gt;
        print(&amp;quot;Lots of cake!&amp;quot;)&lt;br /&gt;
    elif cake_slices_left == 2:&lt;br /&gt;
        print(&amp;quot;One slice gone!&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(&amp;quot;Little to no cake left!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== An Example Python Script ===&lt;br /&gt;
&lt;br /&gt;
In my mind, there's no better way to learn Python than to be immersed in a simple example script.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
print(&amp;quot;Hello World&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
fruits = [&amp;quot;apple&amp;quot;, &amp;quot;banana&amp;quot;, &amp;quot;cherry&amp;quot;, &amp;quot;date&amp;quot;]&lt;br /&gt;
for fruit in fruits:&lt;br /&gt;
    print(f&amp;quot;I always love to eat a fresh {fruit}&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Map the fruits list over to a new list containing the length of the fruit strings:&lt;br /&gt;
fruit_size = [len(fruit) for fruit in fruits]&lt;br /&gt;
&lt;br /&gt;
avg_fruit_size = sum(fruit_size) / len(fruit_size)&lt;br /&gt;
print(f&amp;quot;The average fruit string length is {avg_fruit_size:.2f}.&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some things to notice:&lt;br /&gt;
&lt;br /&gt;
* Printing is achieved using the &amp;lt;code&amp;gt;print()&amp;lt;/code&amp;gt; function.&lt;br /&gt;
* Comments start with a pound symbol &amp;lt;code&amp;gt;#&amp;lt;/code&amp;gt;.&lt;br /&gt;
* We can transform/map a list to a new list in just one line!&lt;br /&gt;
&lt;br /&gt;
For some more examples, see [https://wiki.python.org/moin/SimplePrograms the Python wiki].&lt;br /&gt;
&lt;br /&gt;
=== A Few Gotchas ===&lt;br /&gt;
&lt;br /&gt;
Here are a few things you may not expect when starting out with Python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Strings can be delimited using either single quotes (&amp;lt;code&amp;gt;'&amp;lt;/code&amp;gt;) or double quotes (&amp;lt;code&amp;gt;&amp;quot;&amp;lt;/code&amp;gt;), so &amp;lt;code&amp;gt;'Python'&amp;lt;/code&amp;gt; is the same as &amp;lt;code&amp;gt;&amp;quot;Python&amp;quot;&amp;lt;/code&amp;gt;. You can also use three sets of quotes (single or double again) to delineate a multiple-line string, like so:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
long_string = &amp;quot;&amp;quot;&amp;quot;This&lt;br /&gt;
is my&lt;br /&gt;
very long&lt;br /&gt;
multiple-line&lt;br /&gt;
string&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
To compare the equality of two objects, use the &amp;lt;code&amp;gt;==&amp;lt;/code&amp;gt; operator. To compare the identity of two objects (i.e. whether or not they are literally the same object, at the same place in memory), use the &amp;lt;code&amp;gt;is&amp;lt;/code&amp;gt; operator. These correspond, respectively to &amp;lt;code&amp;gt;.equals()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;==&amp;lt;/code&amp;gt; in Java.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
The &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt; operator performs floating-point division, not integer division, even when both its arguments are integers. If you want to do integer division, use the &amp;lt;code&amp;gt;//&amp;lt;/code&amp;gt; operator. Let's look at an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
9   / 10    == 0.9 # Floating-point division&lt;br /&gt;
9.0 / 10.0  == 0.9 # Floating-point division&lt;br /&gt;
9   // 10   == 0   # Integer division&lt;br /&gt;
9.0 // 10.0 == 0.0 # Integer division, even though the resulting value is a float&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
As discussed in the section [[#Python's_Type_System|Python's Type System]], you can't combine strings and numbers using the &amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt; operator. Instead, you'll have to use one of the following methods of string formatting:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
# Technique 1 – printf-style Formatting&lt;br /&gt;
# This is a classic style of string formatting, used in many programming languages, including in Java's String.format.&lt;br /&gt;
&amp;quot;You scored %d out of %d!&amp;quot; % (score, questions)&lt;br /&gt;
&lt;br /&gt;
# Technique 2 – str.format&lt;br /&gt;
&amp;quot;You scored {} out of {}!&amp;quot;.format(score, questions)&lt;br /&gt;
&lt;br /&gt;
# Technique 3 – f-strings&lt;br /&gt;
# These were only introduced in Python 3.6 but they're very convenient.&lt;br /&gt;
f&amp;quot;You scored {score} out of {questions}!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Technique 4 - String Concatenation&lt;br /&gt;
# This is fine for small things, but for more complicated stuff, use one of the other techniques.&lt;br /&gt;
&amp;quot;You scored &amp;quot; + str(score) + &amp;quot; out of &amp;quot; + str(questions) + &amp;quot;!&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
Define functions using the &amp;lt;code&amp;gt;def&amp;lt;/code&amp;gt; keyword:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello(name):&lt;br /&gt;
    print(f&amp;quot;Hello, {name}!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Invoke functions using parentheses:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
hello(&amp;quot;Batman&amp;quot;)&lt;br /&gt;
hello(&amp;quot;Superman&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Functions can have optional arguments; however, these must come after any required arguments:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello(name=&amp;quot;User&amp;quot;):&lt;br /&gt;
    print(f&amp;quot;Hello, {name}!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
hello() # Prints &amp;quot;Hello, User!&amp;quot;&lt;br /&gt;
hello(&amp;quot;Sarah&amp;quot;) # Prints &amp;quot;Hello, Sarah!&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Functions are just regular objects in Python, meaning you can do stuff like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello(name=&amp;quot;User&amp;quot;):&lt;br /&gt;
    print(f&amp;quot;Hello, {name}!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
greeting = hello&lt;br /&gt;
&lt;br /&gt;
greeting(&amp;quot;Siwei&amp;quot;) # Prints &amp;quot;Hello, Siwei!&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Collection Types ===&lt;br /&gt;
Python has a few basic, built-in collection types. They each have their own special use cases, but they share a lot of similarities. All built-in data structures in Python are zero-indexed, for instance.&lt;br /&gt;
&lt;br /&gt;
To obtain the number of elements in a collection, use the &amp;lt;code&amp;gt;len()&amp;lt;/code&amp;gt; function, like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pets = ['Dog', 'Cat', 'Fish'] # This is a list; you'll learn about them below.&lt;br /&gt;
&lt;br /&gt;
len(pets) # Returns 3&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check if a collection contains an item, use the &amp;lt;code&amp;gt;in&amp;lt;/code&amp;gt; operator:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pets = ['Dog', 'Cat', 'Fish'] # This is a list; you'll learn about them below.&lt;br /&gt;
&lt;br /&gt;
'Dog' in pets # Returns True&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Helpfully, the Python Software Foundation maintains a page containing the asymptotic complexities of important operations on major Python data structures. It's available [https://wiki.python.org/moin/TimeComplexity here].&lt;br /&gt;
&lt;br /&gt;
==== Lists ====&lt;br /&gt;
&lt;br /&gt;
Unlike languages like Java and C, Python's array-like type doesn't have fixed length. Instead, a &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; is a dynamic array (like Java's &amp;lt;code&amp;gt;ArrayList&amp;lt;/code&amp;gt;) of objects of any type. Here's an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
fruits = [&amp;quot;Apple&amp;quot;, &amp;quot;Pear&amp;quot;, &amp;quot;Orange&amp;quot;] # Lists can be creating by placing their items between square brackets&lt;br /&gt;
&lt;br /&gt;
random_items = ['Apple', 12312, 2.0, [1, 2, 3]] # Lists can contain objects of different types - even other lists!&lt;br /&gt;
&lt;br /&gt;
pets.append('Turtle') # Adds 'Turtle' to the end of pets&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the next few examples, we'll be using the following list:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pets = ['Dog', 'Cat', 'Fish', 'Turtle', 'Lizard', 'Snake']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To access or assign elements of a list, use the &amp;lt;code&amp;gt;[]&amp;lt;/code&amp;gt; operator.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pets[0] # Returns 'Dog'&lt;br /&gt;
pets[1] = 'Cow' # Sets pets[1] to 'Cow'&lt;br /&gt;
pets[1] = 'Cat' # Sets pets[1] back to 'Cat' &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also access or assign lists using negative indices, which will return elements starting from the end of the list:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pets[-1] # Returns 'Snake'&lt;br /&gt;
pets[-2] # Returns 'Lizard'&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also use 'slice notation' to obtain or assign subsets of lists:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pets[start:end] # Returns items from index start to index end - 1.&lt;br /&gt;
pets[start:]    # Returns items from index start to the end of the list, inclusive.&lt;br /&gt;
pets[:end]      # Returns items from the beginning of the list to index end - 1.&lt;br /&gt;
pets[:]         # Returns every item in the list&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There's also a third, optional argument: &amp;lt;code&amp;gt;step&amp;lt;/code&amp;gt;, which lets you jump over values:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pets[start:end:step] # Returns items from index start to index end - 1, jumping step values at a time&lt;br /&gt;
&lt;br /&gt;
# Examples:&lt;br /&gt;
pets[1:5:2] # Returns items from index 1 to index 4, jumping 2 at a time, so ['Cat', 'Turtle']&lt;br /&gt;
pets[::3] # Returns all items in the list, jumping 3 at a time, so ['Dog', 'Turtle']&lt;br /&gt;
pets[::-1] # Returns all items in the list, jumping -1 at a time. This reverses the list, so ['Snake', 'Lizard', 'Turtle', 'Fish', 'Cat', 'Dog']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lists have all the performance characteristics you'd expect of a dynamic array - constant-time indexing, amortized constant-time appends, and so on.&lt;br /&gt;
&lt;br /&gt;
==== Tuples ====&lt;br /&gt;
&lt;br /&gt;
Python has a special data type called &amp;lt;code&amp;gt;tuple&amp;lt;/code&amp;gt;, which is exactly the same as a list except for the fact that it cannot be modified, so you can't append or replace items.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
cities = ('St. Louis', 'Los Angeles', 'Seattle') # Tuples are defined using parentheses.&lt;br /&gt;
numbers = 1, 2, 3 # You can also omit the parentheses if it's unambiguous&lt;br /&gt;
single_item_tuple = (1,) # To make a tuple with only one item, put a comma after it&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tuples also enable you to have multiple return values from a function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def compute_length(string):&lt;br /&gt;
    str_len = len(string)&lt;br /&gt;
    if str_len &amp;lt; 5:&lt;br /&gt;
        return str_len, &amp;quot;short&amp;quot;&lt;br /&gt;
    elif str_len &amp;lt; 40:&lt;br /&gt;
        return str_len, &amp;quot;medium&amp;quot;&lt;br /&gt;
    return str_len, &amp;quot;long&amp;quot;&lt;br /&gt;
&lt;br /&gt;
length, description = compute_length(&amp;quot;Four score and seven years ago&amp;quot;)&lt;br /&gt;
print(f&amp;quot;The {description} string is {length} characters long.&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The above example also demonstrates Python's if...elif...else conditional structure.&lt;br /&gt;
&lt;br /&gt;
==== Dictionaries ====&lt;br /&gt;
&lt;br /&gt;
Python has another datatype called a '''dictionary''' (or &amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt;, for short), which are like ''Maps'' in Java, ''associative arrays'' in PHP, and ''object literals'' in JavaScript (coming up soon in Module 6). Essentially, they enable you to use any immutable object as the key in your data structure. &amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt; objects can be created using either the &amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt; function, or by placing items between curly braces, separating keys and values using colons:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
fruits_in_bowl = {&lt;br /&gt;
    'apple': 4,&lt;br /&gt;
    'banana': 2,&lt;br /&gt;
    'cherry': 0,&lt;br /&gt;
    'date': 12&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
apple_count = fruits_in_bowl['apple'] # Equals 4&lt;br /&gt;
&lt;br /&gt;
fruits_in_bowl['pear'] = 9 # Sets 'pear' in the dictionary to 9.&lt;br /&gt;
&lt;br /&gt;
for fruit, num in fruits_in_bowl.items():&lt;br /&gt;
    print(f&amp;quot;There are {num} {fruit}(s) in the bowl.&amp;quot; % (num, fruit))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you only want the keys from a dictionary, you can just iterate over it directly, like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
for fruit in fruits_in_bowl:&lt;br /&gt;
    print(fruit)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you want only the values but not the keys from a dictionary, use &amp;lt;code&amp;gt;my_dictionary.values()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Sets ==== &lt;br /&gt;
A &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt; is an unordered collection of unique items, with constant-time membership checking. &lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
fruits = {'Apple', 'Apple', 'Apple', 'Pear'} # The set removes duplicates, so it will only contain {'Apple', 'Pear'}&lt;br /&gt;
fruits = set(['Apple', 'Apple', 'Apple', 'Pear']) # This line transforms a list into a set&lt;br /&gt;
print('Apple' in fruits) # Constant-time!&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Loops ===&lt;br /&gt;
&lt;br /&gt;
In Python, while loops are written like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
i = 0&lt;br /&gt;
while i &amp;lt; 10:&lt;br /&gt;
    i += 1&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
For loops are written like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pets = ['Dog', 'Cat', 'Fish']&lt;br /&gt;
&lt;br /&gt;
for pet in pets:&lt;br /&gt;
    print(pet)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
To iterate over a range of numbers, you can use the convenient &amp;lt;code&amp;gt;range&amp;lt;/code&amp;gt; function, like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
for i in range(20, 30): # If you omit the first argument to range, it's assumed to be zero.&lt;br /&gt;
    print(i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Note that &amp;lt;code&amp;gt;range&amp;lt;/code&amp;gt; provides a closed-open range. That is to say, it is inclusive of its lower bound and exclusive of its upper bound. To be very explicit about it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
list(range(3, 6)) == [3, 4, 5]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Unlike in other languages you may know, the following is not good practice in Python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pets = ['Dog', 'Cat', 'Fish']&lt;br /&gt;
&lt;br /&gt;
# BAD PRACTICE. DO NOT USE.&lt;br /&gt;
for i in range(len(pets)):&lt;br /&gt;
    pet = pets[i]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Instead, if you need to access both a variable and its index, use the &amp;lt;code&amp;gt;enumerate&amp;lt;/code&amp;gt; function, which allows you to iterate through a group of items, along with their indexes, like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pets = ['Dog', 'Cat', 'Fish']&lt;br /&gt;
&lt;br /&gt;
for index, pet in enumerate(pets):&lt;br /&gt;
    print(f&amp;quot;{pet} at index {index}&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Generator Expressions and Comprehensions ===&lt;br /&gt;
&lt;br /&gt;
A generator is a special kind of object that, basically, represents a collection of items using a value and a function for generating the next value in the collection. In other words, it's a way of creating something that behaves like a list, but which only generates one value at a time, and discards a value when it's done with it. Say, for example, you wanted to do an operation on 10,000,000,000,000 numbers. You could put them all in a list, then iterate over the list, but that would take a lot of memory, plus you'd have to create and fill the entire list before beginning to actually work on your problem. Instead, you'd probably be better off using a generator; telling the computer, essentially: “The starting value is 0. When I ask for the next number in the collection, add 1 to current value and give me that.”&lt;br /&gt;
&lt;br /&gt;
A generator expression is an expression that is evaluated to create a generator. They're super useful. Generator expressions can take two forms – they can be used with and without a condition:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
(EXPRESSION for VARIABLE in ITERABLE) # Unconditional&lt;br /&gt;
(EXPRESSION for VARIABLE in ITERABLE if CONDITION) # Conditional&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
For our purposes, you can think of an iterable as anything you can do a for loop over. Let's take a look at a generator expression in use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
double_even_digits = (number * 2 for number in range(10) if number % 2 == 0)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
That line says that &amp;lt;code&amp;gt;double_even_digits&amp;lt;/code&amp;gt; is every even number between 0 and 10 multiplied by two. Simple enough, right? If we wanted to use all of the numbers, not just the even ones, we could simply remove the if statement at the end of the expression.&lt;br /&gt;
&lt;br /&gt;
Here's the thing, though: if you were to print &amp;lt;code&amp;gt;double_even_digits&amp;lt;/code&amp;gt;, instead of a nice bunch of numbers, you'd get something that looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;generator object &amp;lt;genexpr&amp;gt;&amp;lt;code&amp;gt;at 0x107fc92b0&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That's because generators are lazy! They don't generate their values until those values are needed, and they discard values once they're no longer needed. As a result, '''you can only iterate over a generator once'''. In this case, you can't print out the whole generator, because it hasn't generated all the values yet. You can, however, iterate over the generator, and print its values one at a time, like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
for number in double_even_digits:&lt;br /&gt;
    print(number)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
You can also make a list out of the generator, which will go through all the items in the generator and put them in a list, like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
even_number_list = list(double_even_digits)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
That's actually a great segue to the second topic of this section: comprehensions. A comprehension is just a prettier way to make lists, sets, and dicts out of a generator expressions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# If you want a list:&lt;br /&gt;
list(i for i in range(10) if i % 2 == 0) # Don't do this&lt;br /&gt;
[i for i in range(10) if i % 2 == 0] # Use a list comprehension instead!&lt;br /&gt;
&lt;br /&gt;
# If you want a set:&lt;br /&gt;
set(i for i in range(10) if i % 2 == 0) # Don't do this&lt;br /&gt;
{i for i in range(10) if i % 2 == 0} # Use a set comprehension instead!&lt;br /&gt;
&lt;br /&gt;
# If you want a dict:&lt;br /&gt;
dict((i, i + 1) for i in range(10) if i % 2 == 0) # Don't do this&lt;br /&gt;
{i : i + 1 for i in range(10) if i % 2 == 0} # Use a dict comprehension instead!&lt;br /&gt;
&lt;br /&gt;
# If you want a tuple:&lt;br /&gt;
tuple(i for i in range(10) if i % 2 == 0) # Unfortunately, there's no better way to do this&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In general, generators and comprehensions should be used whenever possible - they're the fastest and easiest way to build collections. If you ever see yourself writing code like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# BAD PRACTICE! DO NOT USE!&lt;br /&gt;
digits = []&lt;br /&gt;
for digit in range(10):&lt;br /&gt;
    digits.append(digit)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Don't do it! Instead, use a generator expression or comprehension, as appropriate. A good way to decide whether a generator expression or comprehension is better for this situation is that, if you're just going to be iterating over your collection once, you should use an generator expression. If not, use a comprehension.&lt;br /&gt;
&lt;br /&gt;
=== Sorting ===&lt;br /&gt;
&lt;br /&gt;
Sorting in Python is frequently performed using the &amp;lt;code&amp;gt;sorted&amp;lt;/code&amp;gt; function, which takes two arguments: an iterable (anything you can do a for-loop over, including lists and tuples) and a function used to evaluate each item. If the function is omitted, Python will try to sort the lists by value.&lt;br /&gt;
&lt;br /&gt;
The following example demonstrates using an inline function, which Python calls a ''lambda''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
fruits = ['apple', 'banana', 'cherry', 'date']&lt;br /&gt;
&lt;br /&gt;
# sort the fruits by string length&lt;br /&gt;
new_fruits = sorted(fruits, key=lambda v: len(v) // 2)&lt;br /&gt;
&lt;br /&gt;
print(new_fruits) # ['date', 'apple', 'banana', 'cherry']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Alternatively, you can sort a &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; using the &amp;lt;code&amp;gt;.sort&amp;lt;/code&amp;gt; method. This is faster than calling &amp;lt;code&amp;gt;sorted&amp;lt;/code&amp;gt;, but it modifies the list in-place and returns &amp;lt;code&amp;gt;None&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
fruits = ['apple', 'banana', 'cherry', 'date']&lt;br /&gt;
fruits.sort()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
=== Import ===&lt;br /&gt;
&lt;br /&gt;
If you want to use functions from other libraries (including ones that you install using pip), use &amp;lt;code&amp;gt;import&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
current_time = time.localtime()&lt;br /&gt;
print(time.strftime('%a, %d %b %Y %H:%M:%S', current_time))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you want to pull the functions out of their namespace, you can use &amp;lt;code&amp;gt;from ___ import ___&amp;lt;/code&amp;gt; syntax:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from time import localtime, strftime&lt;br /&gt;
&lt;br /&gt;
current_time = localtime()&lt;br /&gt;
print(strftime('%a, %d %b %Y %H:%M:%S', current_time))&lt;br /&gt;
&lt;br /&gt;
# Be aware that this technique, although convenient, may cause unexpected behavior if the function names that you're pulling out of the namespace are already used for other purposes in Python.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
=== File I/O ===&lt;br /&gt;
&lt;br /&gt;
You can read an entire file into a variable like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
f = open(&amp;quot;example.txt&amp;quot;)&lt;br /&gt;
file_contents = f.read()&lt;br /&gt;
&lt;br /&gt;
f.close() # free up memory when we're finished with the file&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
A better option is to use a with-block, which handles opening and closing the file for you automatically:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
with open(&amp;quot;example.txt&amp;quot;) as f:&lt;br /&gt;
    file_contents = f.read()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
You can read a file line-by-line like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
with open(&amp;quot;example.txt&amp;quot;) as f:&lt;br /&gt;
    for line in f:&lt;br /&gt;
        print(f&amp;quot;Read line: {line.strip()}&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
You can write to a file like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
with open(&amp;quot;example.txt&amp;quot;, &amp;quot;w&amp;quot;) as f:&lt;br /&gt;
    f.write(&amp;quot;Hello\nWorld\n&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Command-Line Arguments ===&lt;br /&gt;
&lt;br /&gt;
Command line arguments are accessible in the variable &amp;lt;code&amp;gt;sys.argv&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The following example shows a program that expects a filename as its argument, and it prints a usage message if the argument is not present ([https://stackoverflow.com/questions/983201/python-and-sys-argv source]).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import sys, os&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv) &amp;lt; 2:&lt;br /&gt;
    sys.exit(f&amp;quot;Usage: {sys.argv[0]} filename&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
filename = sys.argv[1]&lt;br /&gt;
&lt;br /&gt;
if not os.path.exists(filename):&lt;br /&gt;
    sys.exit(f&amp;quot;Error: File '{sys.argv[1]}' not found&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Object-Oriented Programming ===&lt;br /&gt;
&lt;br /&gt;
You can define and use a class like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
class Food:&lt;br /&gt;
    # constructor:&lt;br /&gt;
    def __init__(self, name):&lt;br /&gt;
        self.name = name&lt;br /&gt;
   &lt;br /&gt;
    def format_name(self):&lt;br /&gt;
        return f&amp;quot;Gotta love to eat {self.name}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class Fruit(Food):&lt;br /&gt;
    def get_definition(self):&lt;br /&gt;
        return f&amp;quot;{self.format_name()} (fruit)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
fruit = Fruit(&amp;quot;Cherry&amp;quot;)&lt;br /&gt;
print(fruit.format_name())&lt;br /&gt;
print(fruit.get_definition())&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This is the same example as in [[PHP#Object-Oriented_Programming|the PHP guide]].&lt;br /&gt;
&lt;br /&gt;
Some things to notice:&lt;br /&gt;
&lt;br /&gt;
* Instance methods ''always'' take &amp;lt;code&amp;gt;self&amp;lt;/code&amp;gt; as their first argument, followed by any number of additional parameters. This can be misleading for programmers familiar with other languages, because the number of arguments you feed to the method is actually ''one less than'' the number of declared parameters. Whenever you call a method on a class instance, that instance is implicitly fed into the explicitly-declared &amp;lt;code&amp;gt;self&amp;lt;/code&amp;gt; parameter of the method.&lt;br /&gt;
*: Note that the &amp;lt;code&amp;gt;self&amp;lt;/code&amp;gt; variable has the same purpose as the &amp;lt;code&amp;gt;this&amp;lt;/code&amp;gt; variable in languages like PHP, Java, JavaScript, and C++.&lt;br /&gt;
*There is no need for a &amp;lt;code&amp;gt;new&amp;lt;/code&amp;gt; keyword in Python.&lt;br /&gt;
&lt;br /&gt;
= Footnotes =&lt;br /&gt;
# {{note|interpreted}}This is an oversimplification. If you're interested, here's a quick explanation of how: In CPython (the reference implementation of Python) programs are compiled to bytecode, an intermediate representation, which is then interpreted.&lt;br /&gt;
[[Category:Module 4]]&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=Python&amp;diff=2853</id>
		<title>Python</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=Python&amp;diff=2853"/>
		<updated>2023-01-10T06:09:31Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Pip */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Languages like Java and C++ have lots of rules regarding variable types, syntax, return values, and so on. These can be cumbersome when you are trying to write short, quick scripts to perform tasks. This is where a ''scripting language'' comes into play.&lt;br /&gt;
&lt;br /&gt;
'''Python''' is a language well-suited to rapid prototype development. It is generally an ''interpreted language'', which means that, generally speaking, a Python program is converted line by line into instructions for the computer to execute as the program runs, instead of having a separate compilation step beforehand {{ref|interpreted}}. The syntax is clean, and it is usually clear at first glance what is going on when you write in Python.&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
&lt;br /&gt;
Python may already be installed on your system. To see whether or not it is, enter the command&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ python3 --version&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If it tells you a version of Python '''greater than or equal to 3.6''' then you're good to go. If not, you need to do a quick package install to get it up and running. Using yum, it's just &amp;lt;code&amp;gt;sudo yum install python36&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you'd like to be able to just type &amp;lt;code&amp;gt;python&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;python3&amp;lt;/code&amp;gt;, you can add the following line to the &amp;lt;code&amp;gt;~/.bashrc&amp;lt;/code&amp;gt; file on your instance:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias python=&amp;quot;/usr/bin/python3&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Python 2 vs Python 3 ====&lt;br /&gt;
&lt;br /&gt;
In 2008, a new version of Python – Python 3 – was released, with a number of changes that made it incompatible with the previous version, Python 2. For several years, the Python community was slow to make the change to Python 3, but today, Python 3 is ''the'' standard for new code. The ''only'' reason to write Python 2 code today is because you have to work in an environment or with libraries that do not support Python 3, and that situation is becoming increasingly rare.&lt;br /&gt;
&lt;br /&gt;
'''For CSE 330 (and this guide), you ''must'' use Python 3.6 or greater.'''&lt;br /&gt;
&lt;br /&gt;
=== Pip ===&lt;br /&gt;
&lt;br /&gt;
Linux distributions have package managers like ''Apt'', ''Yum'', and ''YaST''. PHP has a package manager named ''PEAR''. It's now time to introduce Python's leading package manager: '''pip'''.&lt;br /&gt;
&lt;br /&gt;
Once you have pip installed, you can use it to install Python packages. Use the &amp;lt;code&amp;gt;pip-3.6&amp;lt;/code&amp;gt; command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ pip-3.6 install &amp;lt;package_name&amp;gt; # RHEL&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you'd like to be able to just type &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; instead of &amp;lt;code&amp;gt;pip-3.6&amp;lt;/code&amp;gt;, you can add the following line to the &amp;lt;code&amp;gt;~/.bashrc&amp;lt;/code&amp;gt; file on your instance:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
alias pip=&amp;quot;/usr/bin/pip-3.6&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Running Python =&lt;br /&gt;
&lt;br /&gt;
There are two common ways to run Python code: via the console, and via a Python script file.&lt;br /&gt;
&lt;br /&gt;
=== The Python Console ===&lt;br /&gt;
&lt;br /&gt;
The Python console enables you to experiment with code without opening a text editor. To enter the Python console, simply type the ''python'' command at the terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ python3&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
To leave the interactive console, either type &amp;lt;code&amp;gt;quit()&amp;lt;/code&amp;gt; or press &amp;lt;code&amp;gt;Ctrl-D&amp;lt;/code&amp;gt; (on both Mac and Windows).&lt;br /&gt;
&lt;br /&gt;
=== Python Script Files ===&lt;br /&gt;
&lt;br /&gt;
You can also save Python script files for later use. The extension for Python scripts is &amp;lt;code&amp;gt;*.py&amp;lt;/code&amp;gt;. To run a script file, simply feed its path as an argument to the &amp;lt;code&amp;gt;python&amp;lt;/code&amp;gt; command in Terminal:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
$ python3 my_script.py&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Python Syntax and Language Components =&lt;br /&gt;
&lt;br /&gt;
This section contains a very brief overview of Python syntax. For a more comprehensive introduction, see [http://docs.python.org/tutorial/ the Python docs].&lt;br /&gt;
&lt;br /&gt;
=== Python's Type System ===&lt;br /&gt;
&lt;br /&gt;
Python is a dynamically-typed, strongly-typed, and duck-typed language. What does that mean? Well, let's take those categories one by one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
'''Dynamic typing''', in contrast to ''static typing'' means that the types of objects can be changed. In Java, for instance, if you tried to write the following code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
int c = 2;&lt;br /&gt;
c = &amp;quot;fish&amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Your code would fail to compile, because the Java compiler wouldn't allow you to change the type of the variable &amp;lt;code&amp;gt;c&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Python, however, is just fine with that. You can write:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
c = 2&lt;br /&gt;
c = &amp;quot;fish&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And Python will happily do what you ask.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
'''Strong typing''', in contrast to ''weak typing'', means, roughly, that a language won't implicitly convert types for you. So far, you've used a lot of PHP, which is very weakly typed. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;php&amp;quot;&amp;gt;&lt;br /&gt;
echo &amp;quot;10&amp;quot; . 2;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In PHP, this works just fine. The PHP interpreter sees that &amp;lt;code&amp;gt;2&amp;lt;/code&amp;gt; is an int, and silently converts it to a string for you, so that &amp;lt;code&amp;gt;&amp;quot;10&amp;quot;. 2&amp;lt;/code&amp;gt; equals &amp;lt;code&amp;gt;&amp;quot;102&amp;quot;&amp;lt;/code&amp;gt;. The problem with weak typing is that it can make it unclear to the programmer why things are happening the way they are. For instance, in PHP, the expression &amp;lt;code&amp;gt;&amp;quot;10&amp;quot; == 10&amp;lt;/code&amp;gt; is true, which can be less than obvious. Python, however, tries to disallow that sort of thing:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&amp;quot;10&amp;quot; + &amp;quot;10&amp;quot; # Allowed – concatenates the two strings.&lt;br /&gt;
10   +  10  # Allowed – adds the two ints.&lt;br /&gt;
&amp;quot;10&amp;quot; +  10  # Not allowed – raises a TypeError&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Perhaps the one exception to this rule is the relationship between numeric types; it's perfectly fine to add a float to an int, for example.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
'''Duck-typing''' is a little bit different than the other categories, because it doesn't really have a direct opposite. Essentially, duck-typing is the philosophy that &amp;quot;If it walks like a duck, and quacks like a duck, it's a duck.&amp;quot; In programming terms, that means that we often don't care what type an object is, as long as it can do the things we ask.&lt;br /&gt;
&lt;br /&gt;
Let's look at an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# This function doubles the value it's passed.&lt;br /&gt;
def double(thing):&lt;br /&gt;
    return thing + thing&lt;br /&gt;
double(10) # Returns 20&lt;br /&gt;
double(&amp;quot;fish&amp;quot;) # Returns &amp;quot;fishfish&amp;quot;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If this were Java, we'd have to write two different methods here: one for things of type &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;, and one for things of type &amp;lt;code&amp;gt;String&amp;lt;/code&amp;gt;. Since this is Python, though, we don't have to do that. Instead, Python lets us say, essentially: &amp;quot;This function uses the &amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt; operator, so you can pass whatever object you want to the function, as long as the function supports the &amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt; operator&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
To quote [https://groups.google.com/forum/?hl=en#!msg/comp.lang.python/CCs2oJdyuzc/NYjla5HKMOIJ Alex Martelli], one of the key people in the Python project,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&amp;quot;[Don't] check whether it IS-a duck: check whether it QUACKS-like-a duck, WALKS-like-a duck, etc, etc, depending on exactly what subset of duck-like behaviour you need.&amp;quot;&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Basic Types ===&lt;br /&gt;
&lt;br /&gt;
In Python, the basic scalar types are:&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt; – a string.&lt;br /&gt;
# &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; – an integer object with unlimited digits.&lt;br /&gt;
# &amp;lt;code&amp;gt;bool&amp;lt;/code&amp;gt; – a Boolean value.&lt;br /&gt;
# &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt; – a floating point number; generally equivalent to &amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt; in Java.&lt;br /&gt;
# &amp;lt;code&amp;gt;bytes&amp;lt;/code&amp;gt; – represents a collection of bytes; you're unlikely to use this often.&lt;br /&gt;
&lt;br /&gt;
Casting is done in the C style - to parse an &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; from a string, for instance, you'd write &amp;lt;code&amp;gt;int(&amp;quot;123&amp;quot;)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Basic Control Flow ===&lt;br /&gt;
In Python, blocks of code are delineated using colons and indentation instead of curly braces. '''''That means that proper indentation is mandatory.''''' Every time you use a colon, you must indent one step further, and every time a block ends, you must unindent a step.&lt;br /&gt;
&lt;br /&gt;
Conditional statements are done using the &amp;lt;code&amp;gt;if&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;elif&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;else&amp;lt;/code&amp;gt; operators, like in the example below - pay attention to the indentation:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
cookies_left = 10&lt;br /&gt;
cake_slices_left = 3&lt;br /&gt;
if cookies_left &amp;gt; 10:&lt;br /&gt;
    print(&amp;quot;Lots of cookies!&amp;quot;)&lt;br /&gt;
elif cookies_left &amp;gt; 8:&lt;br /&gt;
    print(&amp;quot;Plenty left!&amp;quot;)&lt;br /&gt;
elif cookies_left == 5:&lt;br /&gt;
    print(&amp;quot;Halfway done!&amp;quot;)&lt;br /&gt;
else:&lt;br /&gt;
    if cake_slices_left == 3:&lt;br /&gt;
        print(&amp;quot;Lots of cake!&amp;quot;)&lt;br /&gt;
    elif cake_slices_left == 2:&lt;br /&gt;
        print(&amp;quot;One slice gone!&amp;quot;)&lt;br /&gt;
    else:&lt;br /&gt;
        print(&amp;quot;Little to no cake left!&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== An Example Python Script ===&lt;br /&gt;
&lt;br /&gt;
In my mind, there's no better way to learn Python than to be immersed in a simple example script.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
print(&amp;quot;Hello World&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
fruits = [&amp;quot;apple&amp;quot;, &amp;quot;banana&amp;quot;, &amp;quot;cherry&amp;quot;, &amp;quot;date&amp;quot;]&lt;br /&gt;
for fruit in fruits:&lt;br /&gt;
    print(f&amp;quot;I always love to eat a fresh {fruit}&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# Map the fruits list over to a new list containing the length of the fruit strings:&lt;br /&gt;
fruit_size = [len(fruit) for fruit in fruits]&lt;br /&gt;
&lt;br /&gt;
avg_fruit_size = sum(fruit_size) / len(fruit_size)&lt;br /&gt;
print(f&amp;quot;The average fruit string length is {avg_fruit_size:.2f}.&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some things to notice:&lt;br /&gt;
&lt;br /&gt;
* Printing is achieved using the &amp;lt;code&amp;gt;print()&amp;lt;/code&amp;gt; function.&lt;br /&gt;
* Comments start with a pound symbol &amp;lt;code&amp;gt;#&amp;lt;/code&amp;gt;.&lt;br /&gt;
* We can transform/map a list to a new list in just one line!&lt;br /&gt;
&lt;br /&gt;
For some more examples, see [https://wiki.python.org/moin/SimplePrograms the Python wiki].&lt;br /&gt;
&lt;br /&gt;
=== A Few Gotchas ===&lt;br /&gt;
&lt;br /&gt;
Here are a few things you may not expect when starting out with Python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
Strings can be delimited using either single quotes (&amp;lt;code&amp;gt;'&amp;lt;/code&amp;gt;) or double quotes (&amp;lt;code&amp;gt;&amp;quot;&amp;lt;/code&amp;gt;), so &amp;lt;code&amp;gt;'Python'&amp;lt;/code&amp;gt; is the same as &amp;lt;code&amp;gt;&amp;quot;Python&amp;quot;&amp;lt;/code&amp;gt;. You can also use three sets of quotes (single or double again) to delineate a multiple-line string, like so:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
long_string = &amp;quot;&amp;quot;&amp;quot;This&lt;br /&gt;
is my&lt;br /&gt;
very long&lt;br /&gt;
multiple-line&lt;br /&gt;
string&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
To compare the equality of two objects, use the &amp;lt;code&amp;gt;==&amp;lt;/code&amp;gt; operator. To compare the identity of two objects (i.e. whether or not they are literally the same object, at the same place in memory), use the &amp;lt;code&amp;gt;is&amp;lt;/code&amp;gt; operator. These correspond, respectively to &amp;lt;code&amp;gt;.equals()&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;==&amp;lt;/code&amp;gt; in Java.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
The &amp;lt;code&amp;gt;/&amp;lt;/code&amp;gt; operator performs floating-point division, not integer division, even when both its arguments are integers. If you want to do integer division, use the &amp;lt;code&amp;gt;//&amp;lt;/code&amp;gt; operator. Let's look at an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
9   / 10    == 0.9 # Floating-point division&lt;br /&gt;
9.0 / 10.0  == 0.9 # Floating-point division&lt;br /&gt;
9   // 10   == 0   # Integer division&lt;br /&gt;
9.0 // 10.0 == 0.0 # Integer division, even though the resulting value is a float&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&lt;br /&gt;
As discussed in the section [[#Python's_Type_System|Python's Type System]], you can't combine strings and numbers using the &amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt; operator. Instead, you'll have to use one of the following methods of string formatting:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
# Technique 1 – printf-style Formatting&lt;br /&gt;
# This is a classic style of string formatting, used in many programming languages, including in Java's String.format.&lt;br /&gt;
&amp;quot;You scored %d out of %d!&amp;quot; % (score, questions)&lt;br /&gt;
&lt;br /&gt;
# Technique 2 – str.format&lt;br /&gt;
&amp;quot;You scored {} out of {}!&amp;quot;.format(score, questions)&lt;br /&gt;
&lt;br /&gt;
# Technique 3 – f-strings&lt;br /&gt;
# These were only introduced in Python 3.6 but they're very convenient.&lt;br /&gt;
f&amp;quot;You scored {score} out of {questions}!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
# Technique 4 - String Concatenation&lt;br /&gt;
# This is fine for small things, but for more complicated stuff, use one of the other techniques.&lt;br /&gt;
&amp;quot;You scored &amp;quot; + str(score) + &amp;quot; out of &amp;quot; + str(questions) + &amp;quot;!&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Functions ===&lt;br /&gt;
&lt;br /&gt;
Define functions using the &amp;lt;code&amp;gt;def&amp;lt;/code&amp;gt; keyword:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello(name):&lt;br /&gt;
    print(f&amp;quot;Hello, {name}!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Invoke functions using parentheses:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
hello(&amp;quot;Batman&amp;quot;)&lt;br /&gt;
hello(&amp;quot;Superman&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Functions can have optional arguments; however, these must come after any required arguments:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello(name=&amp;quot;User&amp;quot;):&lt;br /&gt;
    print(f&amp;quot;Hello, {name}!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
hello() # Prints &amp;quot;Hello, User!&amp;quot;&lt;br /&gt;
hello(&amp;quot;Sarah&amp;quot;) # Prints &amp;quot;Hello, Sarah!&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Functions are just regular objects in Python, meaning you can do stuff like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def hello(name=&amp;quot;User&amp;quot;):&lt;br /&gt;
    print(f&amp;quot;Hello, {name}!&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
greeting = hello&lt;br /&gt;
&lt;br /&gt;
greeting(&amp;quot;Siwei&amp;quot;) # Prints &amp;quot;Hello, Siwei!&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Collection Types ===&lt;br /&gt;
Python has a few basic, built-in collection types. They each have their own special use cases, but they share a lot of similarities. All built-in data structures in Python are zero-indexed, for instance.&lt;br /&gt;
&lt;br /&gt;
To obtain the number of elements in a collection, use the &amp;lt;code&amp;gt;len()&amp;lt;/code&amp;gt; function, like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pets = ['Dog', 'Cat', 'Fish'] # This is a list; you'll learn about them below.&lt;br /&gt;
&lt;br /&gt;
len(pets) # Returns 3&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check if a collection contains an item, use the &amp;lt;code&amp;gt;in&amp;lt;/code&amp;gt; operator:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pets = ['Dog', 'Cat', 'Fish'] # This is a list; you'll learn about them below.&lt;br /&gt;
&lt;br /&gt;
'Dog' in pets # Returns True&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Helpfully, the Python Software Foundation maintains a page containing the asymptotic complexities of important operations on major Python data structures. It's available [https://wiki.python.org/moin/TimeComplexity here].&lt;br /&gt;
&lt;br /&gt;
==== Lists ====&lt;br /&gt;
&lt;br /&gt;
Unlike languages like Java and C, Python's array-like type doesn't have fixed length. Instead, a &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; is a dynamic array (like Java's &amp;lt;code&amp;gt;ArrayList&amp;lt;/code&amp;gt;) of objects of any type. Here's an example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
fruits = [&amp;quot;Apple&amp;quot;, &amp;quot;Pear&amp;quot;, &amp;quot;Orange&amp;quot;] # Lists can be creating by placing their items between square brackets&lt;br /&gt;
&lt;br /&gt;
random_items = ['Apple', 12312, 2.0, [1, 2, 3]] # Lists can contain objects of different types - even other lists!&lt;br /&gt;
&lt;br /&gt;
pets.append('Turtle') # Adds 'Turtle' to the end of pets&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the next few examples, we'll be using the following list:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pets = ['Dog', 'Cat', 'Fish', 'Turtle', 'Lizard', 'Snake']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To access or assign elements of a list, use the &amp;lt;code&amp;gt;[]&amp;lt;/code&amp;gt; operator.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pets[0] # Returns 'Dog'&lt;br /&gt;
pets[1] = 'Cow' # Sets pets[1] to 'Cow'&lt;br /&gt;
pets[1] = 'Cat' # Sets pets[1] back to 'Cat' &lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also access or assign lists using negative indices, which will return elements starting from the end of the list:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pets[-1] # Returns 'Snake'&lt;br /&gt;
pets[-2] # Returns 'Lizard'&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also use 'slice notation' to obtain or assign subsets of lists:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pets[start:end] # Returns items from index start to index end - 1.&lt;br /&gt;
pets[start:]    # Returns items from index start to the end of the list, inclusive.&lt;br /&gt;
pets[:end]      # Returns items from the beginning of the list to index end - 1.&lt;br /&gt;
pets[:]         # Returns every item in the list&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There's also a third, optional argument: &amp;lt;code&amp;gt;step&amp;lt;/code&amp;gt;, which lets you jump over values:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pets[start:end:step] # Returns items from index start to index end - 1, jumping step values at a time&lt;br /&gt;
&lt;br /&gt;
# Examples:&lt;br /&gt;
pets[1:5:2] # Returns items from index 1 to index 4, jumping 2 at a time, so ['Cat', 'Turtle']&lt;br /&gt;
pets[::3] # Returns all items in the list, jumping 3 at a time, so ['Dog', 'Turtle']&lt;br /&gt;
pets[::-1] # Returns all items in the list, jumping -1 at a time. This reverses the list, so ['Snake', 'Lizard', 'Turtle', 'Fish', 'Cat', 'Dog']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Lists have all the performance characteristics you'd expect of a dynamic array - constant-time indexing, amortized constant-time appends, and so on.&lt;br /&gt;
&lt;br /&gt;
==== Tuples ====&lt;br /&gt;
&lt;br /&gt;
Python has a special data type called &amp;lt;code&amp;gt;tuple&amp;lt;/code&amp;gt;, which is exactly the same as a list except for the fact that it cannot be modified, so you can't append or replace items.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
cities = ('St. Louis', 'Los Angeles', 'Seattle') # Tuples are defined using parentheses.&lt;br /&gt;
numbers = 1, 2, 3 # You can also omit the parentheses if it's unambiguous&lt;br /&gt;
single_item_tuple = (1,) # To make a tuple with only one item, put a comma after it&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Tuples also enable you to have multiple return values from a function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
def compute_length(string):&lt;br /&gt;
    str_len = len(string)&lt;br /&gt;
    if str_len &amp;lt; 5:&lt;br /&gt;
        return str_len, &amp;quot;short&amp;quot;&lt;br /&gt;
    elif str_len &amp;lt; 40:&lt;br /&gt;
        return str_len, &amp;quot;medium&amp;quot;&lt;br /&gt;
    return str_len, &amp;quot;long&amp;quot;&lt;br /&gt;
&lt;br /&gt;
length, description = compute_length(&amp;quot;Four score and seven years ago&amp;quot;)&lt;br /&gt;
print(f&amp;quot;The {description} string is {length} characters long.&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The above example also demonstrates Python's if...elif...else conditional structure.&lt;br /&gt;
&lt;br /&gt;
==== Dictionaries ====&lt;br /&gt;
&lt;br /&gt;
Python has another datatype called a '''dictionary''' (or &amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt;, for short), which are like ''Maps'' in Java, ''associative arrays'' in PHP, and ''object literals'' in JavaScript (coming up soon in Module 6). Essentially, they enable you to use any immutable object as the key in your data structure. &amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt; objects can be created using either the &amp;lt;code&amp;gt;dict&amp;lt;/code&amp;gt; function, or by placing items between curly braces, separating keys and values using colons:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
fruits_in_bowl = {&lt;br /&gt;
    'apple': 4,&lt;br /&gt;
    'banana': 2,&lt;br /&gt;
    'cherry': 0,&lt;br /&gt;
    'date': 12&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
apple_count = fruits_in_bowl['apple'] # Equals 4&lt;br /&gt;
&lt;br /&gt;
fruits_in_bowl['pear'] = 9 # Sets 'pear' in the dictionary to 9.&lt;br /&gt;
&lt;br /&gt;
for fruit, num in fruits_in_bowl.items():&lt;br /&gt;
    print(f&amp;quot;There are {num} {fruit}(s) in the bowl.&amp;quot; % (num, fruit))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you only want the keys from a dictionary, you can just iterate over it directly, like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
for fruit in fruits_in_bowl:&lt;br /&gt;
    print(fruit)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you want only the values but not the keys from a dictionary, use &amp;lt;code&amp;gt;my_dictionary.values()&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Sets ==== &lt;br /&gt;
A &amp;lt;code&amp;gt;set&amp;lt;/code&amp;gt; is an unordered collection of unique items, with constant-time membership checking. &lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
fruits = {'Apple', 'Apple', 'Apple', 'Pear'} # The set removes duplicates, so it will only contain {'Apple', 'Pear'}&lt;br /&gt;
fruits = set(['Apple', 'Apple', 'Apple', 'Pear']) # This line transforms a list into a set&lt;br /&gt;
print('Apple' in fruits) # Constant-time!&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Loops ===&lt;br /&gt;
&lt;br /&gt;
In Python, while loops are written like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
i = 0&lt;br /&gt;
while i &amp;lt; 10:&lt;br /&gt;
    i += 1&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
For loops are written like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pets = ['Dog', 'Cat', 'Fish']&lt;br /&gt;
&lt;br /&gt;
for pet in pets:&lt;br /&gt;
    print(pet)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
To iterate over a range of numbers, you can use the convenient &amp;lt;code&amp;gt;range&amp;lt;/code&amp;gt; function, like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
for i in range(20, 30): # If you omit the first argument to range, it's assumed to be zero.&lt;br /&gt;
    print(i)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Note that &amp;lt;code&amp;gt;range&amp;lt;/code&amp;gt; provides a closed-open range. That is to say, it is inclusive of its lower bound and exclusive of its upper bound. To be very explicit about it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
list(range(3, 6)) == [3, 4, 5]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Unlike in other languages you may know, the following is not good practice in Python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pets = ['Dog', 'Cat', 'Fish']&lt;br /&gt;
&lt;br /&gt;
# BAD PRACTICE. DO NOT USE.&lt;br /&gt;
for i in range(len(pets)):&lt;br /&gt;
    pet = pets[i]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Instead, if you need to access both a variable and its index, use the &amp;lt;code&amp;gt;enumerate&amp;lt;/code&amp;gt; function, which allows you to iterate through a group of items, along with their indexes, like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
pets = ['Dog', 'Cat', 'Fish']&lt;br /&gt;
&lt;br /&gt;
for index, pet in enumerate(pets):&lt;br /&gt;
    print(f&amp;quot;{pet} at index {index}&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Generator Expressions and Comprehensions ===&lt;br /&gt;
&lt;br /&gt;
A generator is a special kind of object that, basically, represents a collection of items using a value and a function for generating the next value in the collection. In other words, it's a way of creating something that behaves like a list, but which only generates one value at a time, and discards a value when it's done with it. Say, for example, you wanted to do an operation on 10,000,000,000,000 numbers. You could put them all in a list, then iterate over the list, but that would take a lot of memory, plus you'd have to create and fill the entire list before beginning to actually work on your problem. Instead, you'd probably be better off using a generator; telling the computer, essentially: “The starting value is 0. When I ask for the next number in the collection, add 1 to current value and give me that.”&lt;br /&gt;
&lt;br /&gt;
A generator expression is an expression that is evaluated to create a generator. They're super useful. Generator expressions can take two forms – they can be used with and without a condition:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
(EXPRESSION for VARIABLE in ITERABLE) # Unconditional&lt;br /&gt;
(EXPRESSION for VARIABLE in ITERABLE if CONDITION) # Conditional&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
For our purposes, you can think of an iterable as anything you can do a for loop over. Let's take a look at a generator expression in use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
double_even_digits = (number * 2 for number in range(10) if number % 2 == 0)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
That line says that &amp;lt;code&amp;gt;double_even_digits&amp;lt;/code&amp;gt; is every even number between 0 and 10 multiplied by two. Simple enough, right? If we wanted to use all of the numbers, not just the even ones, we could simply remove the if statement at the end of the expression.&lt;br /&gt;
&lt;br /&gt;
Here's the thing, though: if you were to print &amp;lt;code&amp;gt;double_even_digits&amp;lt;/code&amp;gt;, instead of a nice bunch of numbers, you'd get something that looks like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;generator object &amp;lt;genexpr&amp;gt;&amp;lt;code&amp;gt;at 0x107fc92b0&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
That's because generators are lazy! They don't generate their values until those values are needed, and they discard values once they're no longer needed. As a result, '''you can only iterate over a generator once'''. In this case, you can't print out the whole generator, because it hasn't generated all the values yet. You can, however, iterate over the generator, and print its values one at a time, like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
for number in double_even_digits:&lt;br /&gt;
    print(number)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
You can also make a list out of the generator, which will go through all the items in the generator and put them in a list, like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
even_number_list = list(double_even_digits)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
That's actually a great segue to the second topic of this section: comprehensions. A comprehension is just a prettier way to make lists, sets, and dicts out of a generator expressions.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# If you want a list:&lt;br /&gt;
list(i for i in range(10) if i % 2 == 0) # Don't do this&lt;br /&gt;
[i for i in range(10) if i % 2 == 0] # Use a list comprehension instead!&lt;br /&gt;
&lt;br /&gt;
# If you want a set:&lt;br /&gt;
set(i for i in range(10) if i % 2 == 0) # Don't do this&lt;br /&gt;
{i for i in range(10) if i % 2 == 0} # Use a set comprehension instead!&lt;br /&gt;
&lt;br /&gt;
# If you want a dict:&lt;br /&gt;
dict((i, i + 1) for i in range(10) if i % 2 == 0) # Don't do this&lt;br /&gt;
{i : i + 1 for i in range(10) if i % 2 == 0} # Use a dict comprehension instead!&lt;br /&gt;
&lt;br /&gt;
# If you want a tuple:&lt;br /&gt;
tuple(i for i in range(10) if i % 2 == 0) # Unfortunately, there's no better way to do this&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
In general, generators and comprehensions should be used whenever possible - they're the fastest and easiest way to build collections. If you ever see yourself writing code like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
# BAD PRACTICE! DO NOT USE!&lt;br /&gt;
digits = []&lt;br /&gt;
for digit in range(10):&lt;br /&gt;
    digits.append(digit)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Don't do it! Instead, use a generator expression or comprehension, as appropriate. A good way to decide whether a generator expression or comprehension is better for this situation is that, if you're just going to be iterating over your collection once, you should use an generator expression. If not, use a comprehension.&lt;br /&gt;
&lt;br /&gt;
=== Sorting ===&lt;br /&gt;
&lt;br /&gt;
Sorting in Python is frequently performed using the &amp;lt;code&amp;gt;sorted&amp;lt;/code&amp;gt; function, which takes two arguments: an iterable (anything you can do a for-loop over, including lists and tuples) and a function used to evaluate each item. If the function is omitted, Python will try to sort the lists by value.&lt;br /&gt;
&lt;br /&gt;
The following example demonstrates using an inline function, which Python calls a ''lambda''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
fruits = ['apple', 'banana', 'cherry', 'date']&lt;br /&gt;
&lt;br /&gt;
# sort the fruits by string length&lt;br /&gt;
new_fruits = sorted(fruits, key=lambda v: len(v) // 2)&lt;br /&gt;
&lt;br /&gt;
print(new_fruits) # ['date', 'apple', 'banana', 'cherry']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
Alternatively, you can sort a &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; using the &amp;lt;code&amp;gt;.sort&amp;lt;/code&amp;gt; method. This is faster than calling &amp;lt;code&amp;gt;sorted&amp;lt;/code&amp;gt;, but it modifies the list in-place and returns &amp;lt;code&amp;gt;None&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
fruits = ['apple', 'banana', 'cherry', 'date']&lt;br /&gt;
fruits.sort()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
=== Import ===&lt;br /&gt;
&lt;br /&gt;
If you want to use functions from other libraries (including ones that you install using pip), use &amp;lt;code&amp;gt;import&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import time&lt;br /&gt;
&lt;br /&gt;
current_time = time.localtime()&lt;br /&gt;
print(time.strftime('%a, %d %b %Y %H:%M:%S', current_time))&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
If you want to pull the functions out of their namespace, you can use &amp;lt;code&amp;gt;from ___ import ___&amp;lt;/code&amp;gt; syntax:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from time import localtime, strftime&lt;br /&gt;
&lt;br /&gt;
current_time = localtime()&lt;br /&gt;
print(strftime('%a, %d %b %Y %H:%M:%S', current_time))&lt;br /&gt;
&lt;br /&gt;
# Be aware that this technique, although convenient, may cause unexpected behavior if the function names that you're pulling out of the namespace are already used for other purposes in Python.&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
=== File I/O ===&lt;br /&gt;
&lt;br /&gt;
You can read an entire file into a variable like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
f = open(&amp;quot;example.txt&amp;quot;)&lt;br /&gt;
file_contents = f.read()&lt;br /&gt;
&lt;br /&gt;
f.close() # free up memory when we're finished with the file&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
A better option is to use a with-block, which handles opening and closing the file for you automatically:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
with open(&amp;quot;example.txt&amp;quot;) as f:&lt;br /&gt;
    file_contents = f.read()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
You can read a file line-by-line like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
with open(&amp;quot;example.txt&amp;quot;) as f:&lt;br /&gt;
    for line in f:&lt;br /&gt;
        print(f&amp;quot;Read line: {line.strip()}&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
You can write to a file like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
with open(&amp;quot;example.txt&amp;quot;, &amp;quot;w&amp;quot;) as f:&lt;br /&gt;
    f.write(&amp;quot;Hello\nWorld\n&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Command-Line Arguments ===&lt;br /&gt;
&lt;br /&gt;
Command line arguments are accessible in the variable &amp;lt;code&amp;gt;sys.argv&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The following example shows a program that expects a filename as its argument, and it prints a usage message if the argument is not present ([https://stackoverflow.com/questions/983201/python-and-sys-argv source]).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import sys, os&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv) &amp;lt; 2:&lt;br /&gt;
    sys.exit(f&amp;quot;Usage: {sys.argv[0]} filename&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
filename = sys.argv[1]&lt;br /&gt;
&lt;br /&gt;
if not os.path.exists(filename):&lt;br /&gt;
    sys.exit(f&amp;quot;Error: File '{sys.argv[1]}' not found&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Object-Oriented Programming ===&lt;br /&gt;
&lt;br /&gt;
You can define and use a class like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
class Food:&lt;br /&gt;
    # constructor:&lt;br /&gt;
    def __init__(self, name):&lt;br /&gt;
        self.name = name&lt;br /&gt;
   &lt;br /&gt;
    def format_name(self):&lt;br /&gt;
        return f&amp;quot;Gotta love to eat {self.name}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class Fruit(Food):&lt;br /&gt;
    def get_definition(self):&lt;br /&gt;
        return f&amp;quot;{self.format_name()} (fruit)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
fruit = Fruit(&amp;quot;Cherry&amp;quot;)&lt;br /&gt;
print(fruit.format_name())&lt;br /&gt;
print(fruit.get_definition())&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
This is the same example as in [[PHP#Object-Oriented_Programming|the PHP guide]].&lt;br /&gt;
&lt;br /&gt;
Some things to notice:&lt;br /&gt;
&lt;br /&gt;
* Instance methods ''always'' take &amp;lt;code&amp;gt;self&amp;lt;/code&amp;gt; as their first argument, followed by any number of additional parameters. This can be misleading for programmers familiar with other languages, because the number of arguments you feed to the method is actually ''one less than'' the number of declared parameters. Whenever you call a method on a class instance, that instance is implicitly fed into the explicitly-declared &amp;lt;code&amp;gt;self&amp;lt;/code&amp;gt; parameter of the method.&lt;br /&gt;
*: Note that the &amp;lt;code&amp;gt;self&amp;lt;/code&amp;gt; variable has the same purpose as the &amp;lt;code&amp;gt;this&amp;lt;/code&amp;gt; variable in languages like PHP, Java, JavaScript, and C++.&lt;br /&gt;
*There is no need for a &amp;lt;code&amp;gt;new&amp;lt;/code&amp;gt; keyword in Python.&lt;br /&gt;
&lt;br /&gt;
= Footnotes =&lt;br /&gt;
# {{note|interpreted}}This is an oversimplification. If you're interested, here's a quick explanation of how: In CPython (the reference implementation of Python) programs are compiled to bytecode, an intermediate representation, which is then interpreted.&lt;br /&gt;
[[Category:Module 4]]&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=MySQL_Schema_and_State&amp;diff=2852</id>
		<title>MySQL Schema and State</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=MySQL_Schema_and_State&amp;diff=2852"/>
		<updated>2023-01-10T06:06:12Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Unique Key */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;MySQL is a powerful database that allows for complex logic when manipulating data.  This guide is an introduction and a reference to common SQL queries for schema and state manipulation.&lt;br /&gt;
&lt;br /&gt;
This guide assumes that you already have a working copy of MySQL.  If you don't, read [[Introduction to MySQL]] first.&lt;br /&gt;
&lt;br /&gt;
==Schema ==&lt;br /&gt;
&lt;br /&gt;
The ''schema'' of your database refers to the way that your data is structured and to how bits of data relate to each other.  Every database in your MySQL server has a separate schema, and separate databases should not typically interact with one another.&lt;br /&gt;
&lt;br /&gt;
=== Tables ===&lt;br /&gt;
&lt;br /&gt;
A database contains one or more ''tables''.  Tables contain columns and rows, which you may sometimes call ''fields'' and ''entries''.&lt;br /&gt;
&lt;br /&gt;
You can see all of the tables in the database using this query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
show tables;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you create a table, you should provide information about all of that table's columns within the ''create table'' query.  Here is the general syntax for the query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
create table &amp;lt;TABLENAME&amp;gt; (&lt;br /&gt;
	&amp;lt;FIELDNAME&amp;gt; &amp;lt;DATATYPE&amp;gt; &amp;lt;OPTIONS&amp;gt;,&lt;br /&gt;
	&amp;lt;FIELDNAME&amp;gt; &amp;lt;DATATYPE&amp;gt; &amp;lt;OPTIONS&amp;gt;,&lt;br /&gt;
	&amp;lt;FIELDNAME&amp;gt; &amp;lt;DATATYPE&amp;gt; &amp;lt;OPTIONS&amp;gt;,&lt;br /&gt;
	&amp;lt;FIELDNAME&amp;gt; &amp;lt;DATATYPE&amp;gt; &amp;lt;OPTIONS&amp;gt;&lt;br /&gt;
) &amp;lt;TABLE_OPTIONS&amp;gt;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can get details about an existing table using this query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
describe &amp;lt;TABLENAME&amp;gt;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Data Types ====&lt;br /&gt;
&lt;br /&gt;
Just like a programming language, MySQL has data types.  There are dozens of data types; some of the most common ones are documented below.&lt;br /&gt;
&lt;br /&gt;
===== String Data Types =====&lt;br /&gt;
&lt;br /&gt;
There are four main types of string data types: character, text, blob, and enumerable.&lt;br /&gt;
&lt;br /&gt;
* Character types are useful for short strings, like usernames and e-mail addresses.&lt;br /&gt;
* Text types differ from character types in that behind the scenes, they are not actually stored with the rest of the table row; they are useful for longer blocks of text, like forum posts.&lt;br /&gt;
* Blobs are for binary data, like files.&lt;br /&gt;
* Enumerables are for something that could have one of a set number of values (not more than 65535), like what State a user is from (Alabama, Alaska, and so on).  Enums are also useful for storing boolean data, like '''ENUM('yes','no')'''.  An enum is actually stored as an integer in the database, making queries more efficient.&lt;br /&gt;
&lt;br /&gt;
The syntax for these data types is:&lt;br /&gt;
&lt;br /&gt;
* '''VARCHAR(#)''', a string ''at most'' # characters long, where 0 ≤ # ≤ 65535&lt;br /&gt;
* '''CHAR(#)''', a string ''exactly'' # characters long, where 0 ≤ # ≤ 65535&lt;br /&gt;
* '''TINYTEXT''', a text block at most 255 characters long&lt;br /&gt;
* '''TEXT''', a text block at most 65535 characters long&lt;br /&gt;
* '''LONGTEXT''', a text block at most 4 GB in length&lt;br /&gt;
* '''BLOB''', a binary string at most 65 KB in length&lt;br /&gt;
* '''MEDIUMBLOB''', a binary string at most 16 MB in length&lt;br /&gt;
* '''LONGBLOB''', a binary string at most 4 GB in length&lt;br /&gt;
* '''ENUM('a', 'b', 'c')''', an enumerable with choices a, b, and c&lt;br /&gt;
&lt;br /&gt;
===== Numeric Data Types =====&lt;br /&gt;
&lt;br /&gt;
There are two types of numeric data types that you need to worry about: integers and decimals.  The difference between the two should be pretty self-explanatory.  The syntax for using these data types is:&lt;br /&gt;
&lt;br /&gt;
* '''TINYINT''', an integer ''n'' where -128 ≤ n ≤ 127&lt;br /&gt;
* '''TINYINT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 255&lt;br /&gt;
* '''SMALLINT''', an integer ''n'' where -32,768 ≤ n ≤ 32,767&lt;br /&gt;
* '''SMALLINT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 65,535&lt;br /&gt;
* '''MEDIUMINT''', an integer ''n'' where -8,388,608 ≤ n ≤ 8,388,607&lt;br /&gt;
* '''MEDIUMINT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 16,777,215&lt;br /&gt;
* '''INT''', an integer ''n'' where -2,147,483,648 ≤ n ≤ 2,147,483,647&lt;br /&gt;
* '''INT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 4,294,967,295&lt;br /&gt;
* '''BIGINT''', an integer ''n'' where -9,223,372,036,854,775,808 ≤ n ≤ 9,223,372,036,854,775,807&lt;br /&gt;
* '''BIGINT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 18,446,744,073,709,551,615&lt;br /&gt;
* '''DECIMAL(#a, #b)''', a decimal number at most ''#a'' digits long, ''#b'' of which are after the decimal point.  For example, ''DECIMAL(5,2)'' can contain ''n'' where -999.99 ≤ n ≤ 999.99&lt;br /&gt;
&lt;br /&gt;
When choosing the size of an integer, you should use the ''smallest integer for which you know you will never &amp;quot;run out of room&amp;quot;''.  In most everyday circumstances, '''MEDIUMINT''' should be the biggest you'll need.&lt;br /&gt;
&lt;br /&gt;
===== Temporal Data Types =====&lt;br /&gt;
{{XKCD&lt;br /&gt;
|name=2038&lt;br /&gt;
|id=607&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
MySQL provides a class of data types that specialize in handling dates and times.  The syntax for using date types is:&lt;br /&gt;
&lt;br /&gt;
* '''DATE''', a date ''d'' where &amp;lt;code&amp;gt;1000-01-01&amp;lt;/code&amp;gt; ≤ d ≤ &amp;lt;code&amp;gt;9999-12-31&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''DATETIME''', a date with time ''d'' where &amp;lt;code&amp;gt;1000-01-01 00:00:00&amp;lt;/code&amp;gt; ≤ d ≤ &amp;lt;code&amp;gt;9999-12-31 23:59:59&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''TIMESTAMP''', a date with time ''d'' where &amp;lt;code&amp;gt;1970-01-01 00:00:01 UTC&amp;lt;/code&amp;gt; ≤ d ≤ &amp;lt;code&amp;gt;2038-01-19 03:14:07 UTC&amp;lt;/code&amp;gt; (note: &amp;lt;code&amp;gt;1970-01-01 00:00:01 UTC&amp;lt;/code&amp;gt; is the Unix epoch)&lt;br /&gt;
* '''TIME''', a length of time ''t'' where &amp;lt;code&amp;gt;-838:59:59&amp;lt;/code&amp;gt; ≤ t ≤ &amp;lt;code&amp;gt;838:59:59&amp;lt;/code&amp;gt; (note: you cannot store time to a precision greater than 1 second)&lt;br /&gt;
* '''YEAR''', a year ''y'' where 1901 ≤ y ≤ 2155&lt;br /&gt;
&lt;br /&gt;
Note that '''TIMESTAMP''' is a highly versatile data type that can automatically change whenever a row is updated.  For more information, refer to [http://dev.mysql.com/doc/refman/5.6/en/timestamp-initialization.html the MySQL documentation].&lt;br /&gt;
&lt;br /&gt;
==== Field Options ====&lt;br /&gt;
&lt;br /&gt;
By default, any &amp;quot;cell&amp;quot; in a MySQL table can contain the ''NULL'' value.  If a certain field in your database schema will never contain a null value, you should declare it as '''NOT NULL''' in order to make queries more efficient.&lt;br /&gt;
&lt;br /&gt;
You can also specify a default value for a field.  If you do, when you insert data into the table, it won't be necessary to specify a value for that column.  To specify a default value for a field, use the syntax '''DEFAULT 'DEFAULT-VALUE' '''&lt;br /&gt;
&lt;br /&gt;
==== Create Table Example ====&lt;br /&gt;
&lt;br /&gt;
The following query would create a table called ''employees'' with six columns: employee ID, first name, last name, nickname, department, and the date that they joined the company.  Nickname is the only optional column.  The primary key for the table (see the next section) will be the ''id'' column.  The department will be one of five choices, with the default being CSE.  The storage engine for the table will be InnoDB, and the default charset for the table will be UTF8.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
create table employees (&lt;br /&gt;
	id mediumint unsigned not null auto_increment,&lt;br /&gt;
	first_name varchar(30) not null,&lt;br /&gt;
	last_name varchar(40) not null,&lt;br /&gt;
	nickname varchar(20),&lt;br /&gt;
	department enum('CSE','BME','EECE','ESE','MEMS') not null default 'CSE',&lt;br /&gt;
	joined timestamp not null default current_timestamp,&lt;br /&gt;
	primary key (id)&lt;br /&gt;
) engine = InnoDB default character set = utf8 collate = utf8_general_ci;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Keys ===&lt;br /&gt;
&lt;br /&gt;
When MySQL goes to get data out of a database, it does so using an index, like the index of a textbook.  In tech talk, we call indices ''keys''.&lt;br /&gt;
&lt;br /&gt;
==== Primary Key ====&lt;br /&gt;
&lt;br /&gt;
The '''primary key''' is what MySQL uses to distinguish one row from another.  Every table must have exactly one primary key; no more, no less.&lt;br /&gt;
&lt;br /&gt;
It is common practice to add a column to a table with data type '''mediumint unsigned not null auto_increment''' to serve as the primary key for a table.  The '''auto_increment''' is a neat little feature of MySQL that basically says, &amp;quot;when a new row is inserted into this table, assign it the next-lowest available ID&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
To specify a primary key for a table, use the syntax:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
primary key (column1, column2, column3)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unique Key ====&lt;br /&gt;
&lt;br /&gt;
If you want to specify that all items in a certain column will be unique from each other (like usernames or e-mail addresses), you can use a '''unique key'''.&lt;br /&gt;
&lt;br /&gt;
Because a table can have more than one unique key, you need to give your unique key a name.  It is common practice to name the key after the columns it is indexing, like ''idx_unique_column1_column2''.&lt;br /&gt;
&lt;br /&gt;
The syntax for specifying a unique key is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
unique key INDEX_NAME (column1, column2, column3)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Foreign Key ====&lt;br /&gt;
&lt;br /&gt;
A '''foreign key''' is the most complicated type of MySQL index.  A foreign key says that the values in one column or columns are associated with the values in a column or columns in a ''different table''.&lt;br /&gt;
&lt;br /&gt;
For example, suppose you had two tables, one containing users and the other containing posts on a forum.  There is a one-to-many relationship between users and posts.  You could link a post to a user by having a column in your post table called ''user_id'', which would be a ''foreign key'' to the ''id'' column in your users table.&lt;br /&gt;
&lt;br /&gt;
Foreign keys can be a source of great confusion in developing database schemas.  If you get stuck, keep this tip in mind: '''Foreign Keys should always reference the columns used in the Primary Key of a different table.'''&lt;br /&gt;
&lt;br /&gt;
The syntax for creating a foreign key is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
foreign key (column1, column2, column3) references FOREIGN_TABLENAME (column1, column2, column3)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, in the user-and-post example above, the foreign key declaration would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
foreign key (user_id) references user (id)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Further Reading about Foreign Keys =====&lt;br /&gt;
&lt;br /&gt;
* [[wikipedia:Foreign Key|Wikipedia Entry on Foreign Keys]]&lt;br /&gt;
* [http://www.techrepublic.com/article/an-introduction-to-foreign-keys-and-referential-integrity-in-mysql/6035435 An introductory article on Tech Republic]&lt;br /&gt;
* [http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html MySQL Documentation for Foreign Keys]&lt;br /&gt;
&lt;br /&gt;
==== Syntax for Keys ====&lt;br /&gt;
&lt;br /&gt;
You can define keys in your '''create table''' query, or you can define them later.&lt;br /&gt;
&lt;br /&gt;
If you define them in your '''create table''' query, do so after the column definitions but still inside the parentheses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
create table TABLENAME (&lt;br /&gt;
	column,&lt;br /&gt;
	column,&lt;br /&gt;
	....,&lt;br /&gt;
	primary key (column1, column2, ...),&lt;br /&gt;
	unique key INDEXNAME (column1, column2, ...),&lt;br /&gt;
	foreign key (column1, column2, ...) references FOREIGN_TABLENAME (column1, column2, ...)&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To define indices later, use an '''ALTER TABLE''' query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
alter table TABLENAME add unique key INDEXNAME (column1, column2, ...);&lt;br /&gt;
alter table TABLENAME add foreign key (column1, column2, ...) references FOREIGN_TABLENAME (column1, column2, ...);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== State ==&lt;br /&gt;
&lt;br /&gt;
The ''state'' of your database refers to the data that it holds.  Whenever you insert, update, or delete data, the state of your database changes.&lt;br /&gt;
&lt;br /&gt;
=== Inserting Data from a Query ===&lt;br /&gt;
&lt;br /&gt;
To insert a row (aka ''entry'') into a table, use a query of the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
insert into TABLENAME (column1, column2, column3) values (value1_1, value2_1, value3_1), (value1_2, value2_2, value3_2), ...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, to insert an employee into the table we created earlier, you could use the query&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
insert into employees (first_name, last_name, department) values ('John', 'Doe', 'BME'), ('Keith', 'Jones', 'ESE');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because of the various default and auto_increment values we have specified in our database, the database would now contain the following data:&lt;br /&gt;
&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 | id | first_name | last_name | nickname | department | joined              |&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 |  1 | John       | Doe       | NULL     | BME        | 2012-08-22 22:02:24 |&lt;br /&gt;
 |  2 | Keith      | Jones     | NULL     | ESE        | 2012-08-22 22:02:24 |&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
&lt;br /&gt;
If you want to insert a DATE or DATETIME value into a database, use the YYYY-MM-DD HH:MM:SS format.  The exception is with TIMESTAMP, in which you should use a 16-bit integer representing the number of seconds since January 1, 1970.&lt;br /&gt;
&lt;br /&gt;
=== Inserting Data from a File ===&lt;br /&gt;
&lt;br /&gt;
The '''load data infile''' command populates a table using data stored in a text file. The general form of the command is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
LOAD DATA INFILE 'dataFile.txt' INTO TABLE table_name;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where ''dataFile.txt'' is located relative to the server's data directory if a path name with leading components is given; otherwise, if no leading components are given, the server assumes the file is in the default database's database directory.  If an absolute path is specified, the server uses it. For this command to work, you must issue the following command to grant the FILE privilege to your user:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
GRANT FILE on *.* to 'user'@'host';&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, and quite usefully, you can load data from a local file (a file residing on the same machine as the client) using the LOCAL keyword. When loading data from the local machine you do not need to grant your user the FILE privilege, think about why this might be the case.  (Hint: what is going on behind the scenes when you load the data in from a local machine when your database is hosted on a different machine?)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
LOAD DATA LOCAL INFILE '/home/linus_torvalds/Documents/dataFile.txt' INTO TABLE table_name;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' When the local keyword is used, it is best to specify an absolute path.&lt;br /&gt;
&lt;br /&gt;
'''Additional Note:'''  If we SSH into our EC2 instance and then run the mysql command, the client is the EC2 instance, not the local computer that we SSH from. The LOCAL keyword in this case is allowing us to load files from the EC2 instance, not the local computer that we are using.&lt;br /&gt;
&lt;br /&gt;
By default, the text files are assumed to have tab-delimited columns with column values specified in the same order as they are defined in the table (though you can specify additional/alternative delimiters using additional options).&lt;br /&gt;
&lt;br /&gt;
=== Updating Data ===&lt;br /&gt;
&lt;br /&gt;
To update a row in a table, use a query of the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
update TABLENAME set column1=value1, column2=value2, column3=value3 where CONDITION&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, to set Keith Jones's nickname to &amp;quot;KJ&amp;quot;, you would run the query&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
update employees set nickname='KJ' where id=2;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deleting Data ===&lt;br /&gt;
&lt;br /&gt;
To delete a row from a table, use a query of the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
delete from TABLENAME where CONDITION&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, to delete John Doe from the table, you would run the query&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
delete from employees where id=1;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''DO NOT FORGET THE WHERE CLAUSE!'''  If you do, ''all'' rows will be deleted from your table!&lt;br /&gt;
&lt;br /&gt;
== Selecting Data ==&lt;br /&gt;
&lt;br /&gt;
The most simple query to select data from a table is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select * from TABLENAME;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, in practice, you will almost always want to perform a more advanced query.&lt;br /&gt;
&lt;br /&gt;
=== Selecting Specific Columns ===&lt;br /&gt;
&lt;br /&gt;
In order to save transmission time, you should select only those columns that you need in your application.  The syntax for selecting only certain columns is&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select column1, column2, column3 from TABLENAME;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computation ===&lt;br /&gt;
&lt;br /&gt;
MySQL can perform computation.  For example, if you wanted to select the amount of time that a certain employee has been at the company, you could run the query&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select TIMESTAMPDIFF( second, joined, NOW() ) as time_with_company from employees;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Joins ===&lt;br /&gt;
&lt;br /&gt;
When you have one-to-one, one-to-many, or many-to-many relationships between tables, you will often want to select data from multiple tables in one query.  To do this, use '''joins'''.&lt;br /&gt;
&lt;br /&gt;
Joins are best described by example.  Suppose you had the following tables in a MySQL database:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; describe employees;&lt;br /&gt;
 +------------+---------------------------------------+------+-----+-------------------+----------------+&lt;br /&gt;
 | Field      | Type                                  | Null | Key | Default           | Extra          |&lt;br /&gt;
 +------------+---------------------------------------+------+-----+-------------------+----------------+&lt;br /&gt;
 | id         | mediumint(8) unsigned                 | NO   | PRI | NULL              | auto_increment |&lt;br /&gt;
 | first_name | varchar(30)                           | NO   |     | NULL              |                |&lt;br /&gt;
 | last_name  | varchar(40)                           | NO   |     | NULL              |                |&lt;br /&gt;
 | nickname   | varchar(20)                           | YES  |     | NULL              |                |&lt;br /&gt;
 | department | enum('CSE','BME','EECE','ESE','MEMS') | NO   |     | CSE               |                |&lt;br /&gt;
 | joined     | timestamp                             | NO   |     | CURRENT_TIMESTAMP |                |&lt;br /&gt;
 +------------+---------------------------------------+------+-----+-------------------+----------------+&lt;br /&gt;
 6 rows in set (0.00 sec)&lt;br /&gt;
 &lt;br /&gt;
 mysql&amp;gt; describe projects;&lt;br /&gt;
 +--------------+-----------------------+------+-----+---------+----------------+&lt;br /&gt;
 | Field        | Type                  | Null | Key | Default | Extra          |&lt;br /&gt;
 +--------------+-----------------------+------+-----+---------+----------------+&lt;br /&gt;
 | id           | mediumint(8) unsigned | NO   | PRI | NULL    | auto_increment |&lt;br /&gt;
 | employee_id  | mediumint(8) unsigned | NO   | MUL | NULL    |                |&lt;br /&gt;
 | project_name | tinytext              | NO   |     | NULL    |                |&lt;br /&gt;
 +--------------+-----------------------+------+-----+---------+----------------+&lt;br /&gt;
 3 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
Further, suppose the tables had the following data:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select * from employees;&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 | id | first_name | last_name | nickname | department | joined              |&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 |  1 | John       | Doe       | NULL     | BME        | 2012-08-22 22:02:24 |&lt;br /&gt;
 |  2 | Keith      | Jones     | KK       | ESE        | 2012-08-22 22:02:24 |&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 2 rows in set (0.00 sec)&lt;br /&gt;
 &lt;br /&gt;
 mysql&amp;gt; select * from projects;&lt;br /&gt;
 +----+-------------+-----------------------------------+&lt;br /&gt;
 | id | employee_id | project_name                      |&lt;br /&gt;
 +----+-------------+-----------------------------------+&lt;br /&gt;
 |  1 |           1 | Interview the Chancellor          |&lt;br /&gt;
 |  2 |           1 | Give Presentation in Mumbai       |&lt;br /&gt;
 |  3 |           2 | Publish Research Paper in Journal |&lt;br /&gt;
 +----+-------------+-----------------------------------+&lt;br /&gt;
 3 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
If you ran the following query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	project_name,&lt;br /&gt;
	employees.first_name,&lt;br /&gt;
	employees.last_name&lt;br /&gt;
from projects&lt;br /&gt;
	join employees on (projects.employee_id=employees.id);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You would get the result:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select project_name, employees.first_name, employees.last_name from projects&lt;br /&gt;
     -&amp;gt; join employees on (projects.employee_id=employees.id);&lt;br /&gt;
 +-----------------------------------+------------+-----------+&lt;br /&gt;
 | project_name                      | first_name | last_name |&lt;br /&gt;
 +-----------------------------------+------------+-----------+&lt;br /&gt;
 | Interview the Chancellor          | John       | Doe       |&lt;br /&gt;
 | Give Presentation in Mumbai       | John       | Doe       |&lt;br /&gt;
 | Publish Research Paper in Journal | Keith      | Jones     |&lt;br /&gt;
 +-----------------------------------+------------+-----------+&lt;br /&gt;
 3 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
Isn't that cool?&lt;br /&gt;
&lt;br /&gt;
==== Inner Joins, Left Joins, Right Joins, and Full Joins ====&lt;br /&gt;
&lt;br /&gt;
When you perform a '''JOIN''' like we did above, you are implicitly performing an '''INNER JOIN'''.  However, there may be times when you want to select data in a query even if it doesn't have a complement in the joined table.  For example, suppose Keith Jones cancelled his project.  The projects table now contains the following data:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select * from projects;&lt;br /&gt;
 +----+-------------+-----------------------------+&lt;br /&gt;
 | id | employee_id | project_name                |&lt;br /&gt;
 +----+-------------+-----------------------------+&lt;br /&gt;
 |  1 |           1 | Interview the Chancellor    |&lt;br /&gt;
 |  2 |           1 | Give Presentation in Mumbai |&lt;br /&gt;
 +----+-------------+-----------------------------+&lt;br /&gt;
 2 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
Now, we could run the following query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	count(projects.id) as project_num,&lt;br /&gt;
	employees.first_name,&lt;br /&gt;
	employees.last_name&lt;br /&gt;
from employees&lt;br /&gt;
	join projects on (employees.id=projects.employee_id)&lt;br /&gt;
group by employees.id;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We get the result:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select count(projects.id) as project_num, employees.first_name, employees.last_name from employees&lt;br /&gt;
     -&amp;gt; join projects on (employees.id=projects.employee_id) group by employees.id;&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 | project_num | first_name | last_name |&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 |           2 | John       | Doe       |&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 1 row in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
But where's Keith Jones?  Since Keith Jones didn't have any projects, he was omitted from the result.  This is probably not what we intended to happen.  Instead, you should perform a '''LEFT JOIN''', like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	count(projects.id) as project_num,&lt;br /&gt;
	employees.first_name,&lt;br /&gt;
	employees.last_name&lt;br /&gt;
from employees&lt;br /&gt;
	left join projects on (employees.id=projects.employee_id)&lt;br /&gt;
group by employees.id;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result will now be:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select count(projects.id) as project_num, employees.first_name, employees.last_name from employees&lt;br /&gt;
     -&amp;gt; left join projects on (employees.id=projects.employee_id) group by employees.id;&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 | project_num | first_name | last_name |&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 |           2 | John       | Doe       |&lt;br /&gt;
 |           0 | Keith      | Jones     |&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 2 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
(For more information on COUNT and GROUP BY, see [[#Aggregation Clauses|a later section]].)&lt;br /&gt;
&lt;br /&gt;
You can see that a LEFT JOIN preserves all rows from the &amp;quot;left&amp;quot; table in the join.  Likewise, a RIGHT JOIN preserves all rows from the &amp;quot;right&amp;quot; table.  A FULL JOIN preserves all rows from both tables.&lt;br /&gt;
&lt;br /&gt;
=== WHERE Clauses ===&lt;br /&gt;
&lt;br /&gt;
If you want to select data that satisfies a condition, use a '''WHERE''' clause.&lt;br /&gt;
&lt;br /&gt;
A simple '''WHERE''' clause can use equality, less than, greater than, and most other comparison operators.  For example, the following query selects all last names of employees with an Employee ID of less than 10:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	last_name&lt;br /&gt;
from employees&lt;br /&gt;
where&lt;br /&gt;
	employee_id &amp;lt; 10;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we wanted to select everyone from our employees table whose name started with a J, we could use a '''LIKE''' statement in our '''WHERE''' clause:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	first_name,&lt;br /&gt;
	last_name&lt;br /&gt;
from employees&lt;br /&gt;
where&lt;br /&gt;
	first_name like 'J%';&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The '''LIKE''' clause is SQL's way of letting you perform simple tests on strings.  (SQL's built-in string comparison operations are not as powerful as regular expressions, but they'll get the job done in most everyday situations.)&lt;br /&gt;
&lt;br /&gt;
=== Sorting Data ===&lt;br /&gt;
&lt;br /&gt;
You can sort data using an '''ORDER BY''' clause like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	first_name,&lt;br /&gt;
	last_name&lt;br /&gt;
from employees&lt;br /&gt;
order by last_name asc;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you wanted to select only the first few results from a query, use the '''LIMIT''' clause:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	first_name,&lt;br /&gt;
	last_name&lt;br /&gt;
from employees&lt;br /&gt;
order by last_name asc&lt;br /&gt;
limit 10;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is important to note that the ORDER BY on a field is performed ''after'' aggregation functions.  Currently, there is no way in MySQL to perform sorting ''before'' aggregation has occurred in a single query; we need to resort to nested queries.  (For example, in the baseball example below, it's not easy to select &amp;quot;the player from each team with the highest batting average&amp;quot;.  It's even harder, if not impossible, to select &amp;quot;the ''three'' players from each team with the highest batting averages&amp;quot;.)&lt;br /&gt;
&lt;br /&gt;
=== Aggregation Clauses ===&lt;br /&gt;
&lt;br /&gt;
When performing computations on an entire database, you will probably find yourself wanting to use ''aggregation functions''.  Aggregation functions include:&lt;br /&gt;
&lt;br /&gt;
* '''AVG(column_name)''' to compute the average value of column_name&lt;br /&gt;
* '''STD(column_name)''' to compute the standard deviation of column_name&lt;br /&gt;
* '''SUM(column_name)''' to compute the sum&lt;br /&gt;
* '''MIN(column_name)''' to find the minimum value&lt;br /&gt;
* '''MAX(column_name)''' to fund the maximum value&lt;br /&gt;
* '''COUNT(column_name)''' to count the total number of entries having a not null entry in column_name&lt;br /&gt;
&lt;br /&gt;
For example, if you had a table containing batter averages, you could calculate the mean batter average using this query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since WHERE clauses are performed ''before'' aggregation, you can also perform a query like&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players&lt;br /&gt;
where&lt;br /&gt;
	team_id=5;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to aggregate all rows that share a certain value in an index, use a '''GROUP BY''' clause.  For example, to select the average batter average for all teams, you could do&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players&lt;br /&gt;
group by team_id;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may find yourself wanting to apply a condition after the aggregation has occurred.  You can do this using a '''HAVING''' clause.  For example, the following query would select all baseball teams whose average batter average is more than 300:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players&lt;br /&gt;
group by team_id&lt;br /&gt;
having&lt;br /&gt;
	avg_batter_average &amp;gt; 300;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is perfectly valid to combine WHERE and HAVING clauses in a single query.  For example, the following query first finds all players whose first name starts with &amp;quot;J&amp;quot;, averages their batting averages together by team, and then selects those teams whose average batting average of the &amp;quot;J&amp;quot; players is more than 300; that is, it selects those teams &amp;quot;whose average batting average of players whose first name starts with J is more than 300&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players&lt;br /&gt;
where&lt;br /&gt;
	first_name like &amp;quot;J%&amp;quot;&lt;br /&gt;
group by team_id&lt;br /&gt;
having&lt;br /&gt;
	avg_batter_average &amp;gt; 300;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=MySQL_Schema_and_State&amp;diff=2851</id>
		<title>MySQL Schema and State</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=MySQL_Schema_and_State&amp;diff=2851"/>
		<updated>2023-01-10T06:05:33Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Foreign Key */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;MySQL is a powerful database that allows for complex logic when manipulating data.  This guide is an introduction and a reference to common SQL queries for schema and state manipulation.&lt;br /&gt;
&lt;br /&gt;
This guide assumes that you already have a working copy of MySQL.  If you don't, read [[Introduction to MySQL]] first.&lt;br /&gt;
&lt;br /&gt;
==Schema ==&lt;br /&gt;
&lt;br /&gt;
The ''schema'' of your database refers to the way that your data is structured and to how bits of data relate to each other.  Every database in your MySQL server has a separate schema, and separate databases should not typically interact with one another.&lt;br /&gt;
&lt;br /&gt;
=== Tables ===&lt;br /&gt;
&lt;br /&gt;
A database contains one or more ''tables''.  Tables contain columns and rows, which you may sometimes call ''fields'' and ''entries''.&lt;br /&gt;
&lt;br /&gt;
You can see all of the tables in the database using this query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
show tables;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you create a table, you should provide information about all of that table's columns within the ''create table'' query.  Here is the general syntax for the query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
create table &amp;lt;TABLENAME&amp;gt; (&lt;br /&gt;
	&amp;lt;FIELDNAME&amp;gt; &amp;lt;DATATYPE&amp;gt; &amp;lt;OPTIONS&amp;gt;,&lt;br /&gt;
	&amp;lt;FIELDNAME&amp;gt; &amp;lt;DATATYPE&amp;gt; &amp;lt;OPTIONS&amp;gt;,&lt;br /&gt;
	&amp;lt;FIELDNAME&amp;gt; &amp;lt;DATATYPE&amp;gt; &amp;lt;OPTIONS&amp;gt;,&lt;br /&gt;
	&amp;lt;FIELDNAME&amp;gt; &amp;lt;DATATYPE&amp;gt; &amp;lt;OPTIONS&amp;gt;&lt;br /&gt;
) &amp;lt;TABLE_OPTIONS&amp;gt;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can get details about an existing table using this query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
describe &amp;lt;TABLENAME&amp;gt;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Data Types ====&lt;br /&gt;
&lt;br /&gt;
Just like a programming language, MySQL has data types.  There are dozens of data types; some of the most common ones are documented below.&lt;br /&gt;
&lt;br /&gt;
===== String Data Types =====&lt;br /&gt;
&lt;br /&gt;
There are four main types of string data types: character, text, blob, and enumerable.&lt;br /&gt;
&lt;br /&gt;
* Character types are useful for short strings, like usernames and e-mail addresses.&lt;br /&gt;
* Text types differ from character types in that behind the scenes, they are not actually stored with the rest of the table row; they are useful for longer blocks of text, like forum posts.&lt;br /&gt;
* Blobs are for binary data, like files.&lt;br /&gt;
* Enumerables are for something that could have one of a set number of values (not more than 65535), like what State a user is from (Alabama, Alaska, and so on).  Enums are also useful for storing boolean data, like '''ENUM('yes','no')'''.  An enum is actually stored as an integer in the database, making queries more efficient.&lt;br /&gt;
&lt;br /&gt;
The syntax for these data types is:&lt;br /&gt;
&lt;br /&gt;
* '''VARCHAR(#)''', a string ''at most'' # characters long, where 0 ≤ # ≤ 65535&lt;br /&gt;
* '''CHAR(#)''', a string ''exactly'' # characters long, where 0 ≤ # ≤ 65535&lt;br /&gt;
* '''TINYTEXT''', a text block at most 255 characters long&lt;br /&gt;
* '''TEXT''', a text block at most 65535 characters long&lt;br /&gt;
* '''LONGTEXT''', a text block at most 4 GB in length&lt;br /&gt;
* '''BLOB''', a binary string at most 65 KB in length&lt;br /&gt;
* '''MEDIUMBLOB''', a binary string at most 16 MB in length&lt;br /&gt;
* '''LONGBLOB''', a binary string at most 4 GB in length&lt;br /&gt;
* '''ENUM('a', 'b', 'c')''', an enumerable with choices a, b, and c&lt;br /&gt;
&lt;br /&gt;
===== Numeric Data Types =====&lt;br /&gt;
&lt;br /&gt;
There are two types of numeric data types that you need to worry about: integers and decimals.  The difference between the two should be pretty self-explanatory.  The syntax for using these data types is:&lt;br /&gt;
&lt;br /&gt;
* '''TINYINT''', an integer ''n'' where -128 ≤ n ≤ 127&lt;br /&gt;
* '''TINYINT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 255&lt;br /&gt;
* '''SMALLINT''', an integer ''n'' where -32,768 ≤ n ≤ 32,767&lt;br /&gt;
* '''SMALLINT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 65,535&lt;br /&gt;
* '''MEDIUMINT''', an integer ''n'' where -8,388,608 ≤ n ≤ 8,388,607&lt;br /&gt;
* '''MEDIUMINT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 16,777,215&lt;br /&gt;
* '''INT''', an integer ''n'' where -2,147,483,648 ≤ n ≤ 2,147,483,647&lt;br /&gt;
* '''INT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 4,294,967,295&lt;br /&gt;
* '''BIGINT''', an integer ''n'' where -9,223,372,036,854,775,808 ≤ n ≤ 9,223,372,036,854,775,807&lt;br /&gt;
* '''BIGINT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 18,446,744,073,709,551,615&lt;br /&gt;
* '''DECIMAL(#a, #b)''', a decimal number at most ''#a'' digits long, ''#b'' of which are after the decimal point.  For example, ''DECIMAL(5,2)'' can contain ''n'' where -999.99 ≤ n ≤ 999.99&lt;br /&gt;
&lt;br /&gt;
When choosing the size of an integer, you should use the ''smallest integer for which you know you will never &amp;quot;run out of room&amp;quot;''.  In most everyday circumstances, '''MEDIUMINT''' should be the biggest you'll need.&lt;br /&gt;
&lt;br /&gt;
===== Temporal Data Types =====&lt;br /&gt;
{{XKCD&lt;br /&gt;
|name=2038&lt;br /&gt;
|id=607&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
MySQL provides a class of data types that specialize in handling dates and times.  The syntax for using date types is:&lt;br /&gt;
&lt;br /&gt;
* '''DATE''', a date ''d'' where &amp;lt;code&amp;gt;1000-01-01&amp;lt;/code&amp;gt; ≤ d ≤ &amp;lt;code&amp;gt;9999-12-31&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''DATETIME''', a date with time ''d'' where &amp;lt;code&amp;gt;1000-01-01 00:00:00&amp;lt;/code&amp;gt; ≤ d ≤ &amp;lt;code&amp;gt;9999-12-31 23:59:59&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''TIMESTAMP''', a date with time ''d'' where &amp;lt;code&amp;gt;1970-01-01 00:00:01 UTC&amp;lt;/code&amp;gt; ≤ d ≤ &amp;lt;code&amp;gt;2038-01-19 03:14:07 UTC&amp;lt;/code&amp;gt; (note: &amp;lt;code&amp;gt;1970-01-01 00:00:01 UTC&amp;lt;/code&amp;gt; is the Unix epoch)&lt;br /&gt;
* '''TIME''', a length of time ''t'' where &amp;lt;code&amp;gt;-838:59:59&amp;lt;/code&amp;gt; ≤ t ≤ &amp;lt;code&amp;gt;838:59:59&amp;lt;/code&amp;gt; (note: you cannot store time to a precision greater than 1 second)&lt;br /&gt;
* '''YEAR''', a year ''y'' where 1901 ≤ y ≤ 2155&lt;br /&gt;
&lt;br /&gt;
Note that '''TIMESTAMP''' is a highly versatile data type that can automatically change whenever a row is updated.  For more information, refer to [http://dev.mysql.com/doc/refman/5.6/en/timestamp-initialization.html the MySQL documentation].&lt;br /&gt;
&lt;br /&gt;
==== Field Options ====&lt;br /&gt;
&lt;br /&gt;
By default, any &amp;quot;cell&amp;quot; in a MySQL table can contain the ''NULL'' value.  If a certain field in your database schema will never contain a null value, you should declare it as '''NOT NULL''' in order to make queries more efficient.&lt;br /&gt;
&lt;br /&gt;
You can also specify a default value for a field.  If you do, when you insert data into the table, it won't be necessary to specify a value for that column.  To specify a default value for a field, use the syntax '''DEFAULT 'DEFAULT-VALUE' '''&lt;br /&gt;
&lt;br /&gt;
==== Create Table Example ====&lt;br /&gt;
&lt;br /&gt;
The following query would create a table called ''employees'' with six columns: employee ID, first name, last name, nickname, department, and the date that they joined the company.  Nickname is the only optional column.  The primary key for the table (see the next section) will be the ''id'' column.  The department will be one of five choices, with the default being CSE.  The storage engine for the table will be InnoDB, and the default charset for the table will be UTF8.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
create table employees (&lt;br /&gt;
	id mediumint unsigned not null auto_increment,&lt;br /&gt;
	first_name varchar(30) not null,&lt;br /&gt;
	last_name varchar(40) not null,&lt;br /&gt;
	nickname varchar(20),&lt;br /&gt;
	department enum('CSE','BME','EECE','ESE','MEMS') not null default 'CSE',&lt;br /&gt;
	joined timestamp not null default current_timestamp,&lt;br /&gt;
	primary key (id)&lt;br /&gt;
) engine = InnoDB default character set = utf8 collate = utf8_general_ci;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Keys ===&lt;br /&gt;
&lt;br /&gt;
When MySQL goes to get data out of a database, it does so using an index, like the index of a textbook.  In tech talk, we call indices ''keys''.&lt;br /&gt;
&lt;br /&gt;
==== Primary Key ====&lt;br /&gt;
&lt;br /&gt;
The '''primary key''' is what MySQL uses to distinguish one row from another.  Every table must have exactly one primary key; no more, no less.&lt;br /&gt;
&lt;br /&gt;
It is common practice to add a column to a table with data type '''mediumint unsigned not null auto_increment''' to serve as the primary key for a table.  The '''auto_increment''' is a neat little feature of MySQL that basically says, &amp;quot;when a new row is inserted into this table, assign it the next-lowest available ID&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
To specify a primary key for a table, use the syntax:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
primary key (column1, column2, column3)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unique Key ====&lt;br /&gt;
&lt;br /&gt;
If you want to specify that all items in a certain column will be unique from each other (like usernames or e-mail addresses), you can use a '''unique key'''.&lt;br /&gt;
&lt;br /&gt;
Because a table can have more than one unique key, you need to give your unique key a name.  It is common practice to name the key after the columns it is indexing, like ''idx_unique_column1_column2''.&lt;br /&gt;
&lt;br /&gt;
The syntax for specifying a unique key is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
unique key &amp;lt;INDEX_NAME&amp;gt; (&amp;lt;column1&amp;gt;, &amp;lt;column2&amp;gt;, &amp;lt;column3&amp;gt;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Foreign Key ====&lt;br /&gt;
&lt;br /&gt;
A '''foreign key''' is the most complicated type of MySQL index.  A foreign key says that the values in one column or columns are associated with the values in a column or columns in a ''different table''.&lt;br /&gt;
&lt;br /&gt;
For example, suppose you had two tables, one containing users and the other containing posts on a forum.  There is a one-to-many relationship between users and posts.  You could link a post to a user by having a column in your post table called ''user_id'', which would be a ''foreign key'' to the ''id'' column in your users table.&lt;br /&gt;
&lt;br /&gt;
Foreign keys can be a source of great confusion in developing database schemas.  If you get stuck, keep this tip in mind: '''Foreign Keys should always reference the columns used in the Primary Key of a different table.'''&lt;br /&gt;
&lt;br /&gt;
The syntax for creating a foreign key is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
foreign key (column1, column2, column3) references FOREIGN_TABLENAME (column1, column2, column3)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, in the user-and-post example above, the foreign key declaration would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
foreign key (user_id) references user (id)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Further Reading about Foreign Keys =====&lt;br /&gt;
&lt;br /&gt;
* [[wikipedia:Foreign Key|Wikipedia Entry on Foreign Keys]]&lt;br /&gt;
* [http://www.techrepublic.com/article/an-introduction-to-foreign-keys-and-referential-integrity-in-mysql/6035435 An introductory article on Tech Republic]&lt;br /&gt;
* [http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html MySQL Documentation for Foreign Keys]&lt;br /&gt;
&lt;br /&gt;
==== Syntax for Keys ====&lt;br /&gt;
&lt;br /&gt;
You can define keys in your '''create table''' query, or you can define them later.&lt;br /&gt;
&lt;br /&gt;
If you define them in your '''create table''' query, do so after the column definitions but still inside the parentheses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
create table TABLENAME (&lt;br /&gt;
	column,&lt;br /&gt;
	column,&lt;br /&gt;
	....,&lt;br /&gt;
	primary key (column1, column2, ...),&lt;br /&gt;
	unique key INDEXNAME (column1, column2, ...),&lt;br /&gt;
	foreign key (column1, column2, ...) references FOREIGN_TABLENAME (column1, column2, ...)&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To define indices later, use an '''ALTER TABLE''' query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
alter table TABLENAME add unique key INDEXNAME (column1, column2, ...);&lt;br /&gt;
alter table TABLENAME add foreign key (column1, column2, ...) references FOREIGN_TABLENAME (column1, column2, ...);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== State ==&lt;br /&gt;
&lt;br /&gt;
The ''state'' of your database refers to the data that it holds.  Whenever you insert, update, or delete data, the state of your database changes.&lt;br /&gt;
&lt;br /&gt;
=== Inserting Data from a Query ===&lt;br /&gt;
&lt;br /&gt;
To insert a row (aka ''entry'') into a table, use a query of the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
insert into TABLENAME (column1, column2, column3) values (value1_1, value2_1, value3_1), (value1_2, value2_2, value3_2), ...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, to insert an employee into the table we created earlier, you could use the query&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
insert into employees (first_name, last_name, department) values ('John', 'Doe', 'BME'), ('Keith', 'Jones', 'ESE');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because of the various default and auto_increment values we have specified in our database, the database would now contain the following data:&lt;br /&gt;
&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 | id | first_name | last_name | nickname | department | joined              |&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 |  1 | John       | Doe       | NULL     | BME        | 2012-08-22 22:02:24 |&lt;br /&gt;
 |  2 | Keith      | Jones     | NULL     | ESE        | 2012-08-22 22:02:24 |&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
&lt;br /&gt;
If you want to insert a DATE or DATETIME value into a database, use the YYYY-MM-DD HH:MM:SS format.  The exception is with TIMESTAMP, in which you should use a 16-bit integer representing the number of seconds since January 1, 1970.&lt;br /&gt;
&lt;br /&gt;
=== Inserting Data from a File ===&lt;br /&gt;
&lt;br /&gt;
The '''load data infile''' command populates a table using data stored in a text file. The general form of the command is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
LOAD DATA INFILE 'dataFile.txt' INTO TABLE table_name;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where ''dataFile.txt'' is located relative to the server's data directory if a path name with leading components is given; otherwise, if no leading components are given, the server assumes the file is in the default database's database directory.  If an absolute path is specified, the server uses it. For this command to work, you must issue the following command to grant the FILE privilege to your user:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
GRANT FILE on *.* to 'user'@'host';&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, and quite usefully, you can load data from a local file (a file residing on the same machine as the client) using the LOCAL keyword. When loading data from the local machine you do not need to grant your user the FILE privilege, think about why this might be the case.  (Hint: what is going on behind the scenes when you load the data in from a local machine when your database is hosted on a different machine?)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
LOAD DATA LOCAL INFILE '/home/linus_torvalds/Documents/dataFile.txt' INTO TABLE table_name;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' When the local keyword is used, it is best to specify an absolute path.&lt;br /&gt;
&lt;br /&gt;
'''Additional Note:'''  If we SSH into our EC2 instance and then run the mysql command, the client is the EC2 instance, not the local computer that we SSH from. The LOCAL keyword in this case is allowing us to load files from the EC2 instance, not the local computer that we are using.&lt;br /&gt;
&lt;br /&gt;
By default, the text files are assumed to have tab-delimited columns with column values specified in the same order as they are defined in the table (though you can specify additional/alternative delimiters using additional options).&lt;br /&gt;
&lt;br /&gt;
=== Updating Data ===&lt;br /&gt;
&lt;br /&gt;
To update a row in a table, use a query of the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
update TABLENAME set column1=value1, column2=value2, column3=value3 where CONDITION&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, to set Keith Jones's nickname to &amp;quot;KJ&amp;quot;, you would run the query&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
update employees set nickname='KJ' where id=2;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deleting Data ===&lt;br /&gt;
&lt;br /&gt;
To delete a row from a table, use a query of the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
delete from TABLENAME where CONDITION&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, to delete John Doe from the table, you would run the query&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
delete from employees where id=1;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''DO NOT FORGET THE WHERE CLAUSE!'''  If you do, ''all'' rows will be deleted from your table!&lt;br /&gt;
&lt;br /&gt;
== Selecting Data ==&lt;br /&gt;
&lt;br /&gt;
The most simple query to select data from a table is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select * from TABLENAME;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, in practice, you will almost always want to perform a more advanced query.&lt;br /&gt;
&lt;br /&gt;
=== Selecting Specific Columns ===&lt;br /&gt;
&lt;br /&gt;
In order to save transmission time, you should select only those columns that you need in your application.  The syntax for selecting only certain columns is&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select column1, column2, column3 from TABLENAME;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computation ===&lt;br /&gt;
&lt;br /&gt;
MySQL can perform computation.  For example, if you wanted to select the amount of time that a certain employee has been at the company, you could run the query&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select TIMESTAMPDIFF( second, joined, NOW() ) as time_with_company from employees;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Joins ===&lt;br /&gt;
&lt;br /&gt;
When you have one-to-one, one-to-many, or many-to-many relationships between tables, you will often want to select data from multiple tables in one query.  To do this, use '''joins'''.&lt;br /&gt;
&lt;br /&gt;
Joins are best described by example.  Suppose you had the following tables in a MySQL database:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; describe employees;&lt;br /&gt;
 +------------+---------------------------------------+------+-----+-------------------+----------------+&lt;br /&gt;
 | Field      | Type                                  | Null | Key | Default           | Extra          |&lt;br /&gt;
 +------------+---------------------------------------+------+-----+-------------------+----------------+&lt;br /&gt;
 | id         | mediumint(8) unsigned                 | NO   | PRI | NULL              | auto_increment |&lt;br /&gt;
 | first_name | varchar(30)                           | NO   |     | NULL              |                |&lt;br /&gt;
 | last_name  | varchar(40)                           | NO   |     | NULL              |                |&lt;br /&gt;
 | nickname   | varchar(20)                           | YES  |     | NULL              |                |&lt;br /&gt;
 | department | enum('CSE','BME','EECE','ESE','MEMS') | NO   |     | CSE               |                |&lt;br /&gt;
 | joined     | timestamp                             | NO   |     | CURRENT_TIMESTAMP |                |&lt;br /&gt;
 +------------+---------------------------------------+------+-----+-------------------+----------------+&lt;br /&gt;
 6 rows in set (0.00 sec)&lt;br /&gt;
 &lt;br /&gt;
 mysql&amp;gt; describe projects;&lt;br /&gt;
 +--------------+-----------------------+------+-----+---------+----------------+&lt;br /&gt;
 | Field        | Type                  | Null | Key | Default | Extra          |&lt;br /&gt;
 +--------------+-----------------------+------+-----+---------+----------------+&lt;br /&gt;
 | id           | mediumint(8) unsigned | NO   | PRI | NULL    | auto_increment |&lt;br /&gt;
 | employee_id  | mediumint(8) unsigned | NO   | MUL | NULL    |                |&lt;br /&gt;
 | project_name | tinytext              | NO   |     | NULL    |                |&lt;br /&gt;
 +--------------+-----------------------+------+-----+---------+----------------+&lt;br /&gt;
 3 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
Further, suppose the tables had the following data:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select * from employees;&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 | id | first_name | last_name | nickname | department | joined              |&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 |  1 | John       | Doe       | NULL     | BME        | 2012-08-22 22:02:24 |&lt;br /&gt;
 |  2 | Keith      | Jones     | KK       | ESE        | 2012-08-22 22:02:24 |&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 2 rows in set (0.00 sec)&lt;br /&gt;
 &lt;br /&gt;
 mysql&amp;gt; select * from projects;&lt;br /&gt;
 +----+-------------+-----------------------------------+&lt;br /&gt;
 | id | employee_id | project_name                      |&lt;br /&gt;
 +----+-------------+-----------------------------------+&lt;br /&gt;
 |  1 |           1 | Interview the Chancellor          |&lt;br /&gt;
 |  2 |           1 | Give Presentation in Mumbai       |&lt;br /&gt;
 |  3 |           2 | Publish Research Paper in Journal |&lt;br /&gt;
 +----+-------------+-----------------------------------+&lt;br /&gt;
 3 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
If you ran the following query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	project_name,&lt;br /&gt;
	employees.first_name,&lt;br /&gt;
	employees.last_name&lt;br /&gt;
from projects&lt;br /&gt;
	join employees on (projects.employee_id=employees.id);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You would get the result:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select project_name, employees.first_name, employees.last_name from projects&lt;br /&gt;
     -&amp;gt; join employees on (projects.employee_id=employees.id);&lt;br /&gt;
 +-----------------------------------+------------+-----------+&lt;br /&gt;
 | project_name                      | first_name | last_name |&lt;br /&gt;
 +-----------------------------------+------------+-----------+&lt;br /&gt;
 | Interview the Chancellor          | John       | Doe       |&lt;br /&gt;
 | Give Presentation in Mumbai       | John       | Doe       |&lt;br /&gt;
 | Publish Research Paper in Journal | Keith      | Jones     |&lt;br /&gt;
 +-----------------------------------+------------+-----------+&lt;br /&gt;
 3 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
Isn't that cool?&lt;br /&gt;
&lt;br /&gt;
==== Inner Joins, Left Joins, Right Joins, and Full Joins ====&lt;br /&gt;
&lt;br /&gt;
When you perform a '''JOIN''' like we did above, you are implicitly performing an '''INNER JOIN'''.  However, there may be times when you want to select data in a query even if it doesn't have a complement in the joined table.  For example, suppose Keith Jones cancelled his project.  The projects table now contains the following data:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select * from projects;&lt;br /&gt;
 +----+-------------+-----------------------------+&lt;br /&gt;
 | id | employee_id | project_name                |&lt;br /&gt;
 +----+-------------+-----------------------------+&lt;br /&gt;
 |  1 |           1 | Interview the Chancellor    |&lt;br /&gt;
 |  2 |           1 | Give Presentation in Mumbai |&lt;br /&gt;
 +----+-------------+-----------------------------+&lt;br /&gt;
 2 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
Now, we could run the following query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	count(projects.id) as project_num,&lt;br /&gt;
	employees.first_name,&lt;br /&gt;
	employees.last_name&lt;br /&gt;
from employees&lt;br /&gt;
	join projects on (employees.id=projects.employee_id)&lt;br /&gt;
group by employees.id;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We get the result:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select count(projects.id) as project_num, employees.first_name, employees.last_name from employees&lt;br /&gt;
     -&amp;gt; join projects on (employees.id=projects.employee_id) group by employees.id;&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 | project_num | first_name | last_name |&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 |           2 | John       | Doe       |&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 1 row in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
But where's Keith Jones?  Since Keith Jones didn't have any projects, he was omitted from the result.  This is probably not what we intended to happen.  Instead, you should perform a '''LEFT JOIN''', like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	count(projects.id) as project_num,&lt;br /&gt;
	employees.first_name,&lt;br /&gt;
	employees.last_name&lt;br /&gt;
from employees&lt;br /&gt;
	left join projects on (employees.id=projects.employee_id)&lt;br /&gt;
group by employees.id;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result will now be:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select count(projects.id) as project_num, employees.first_name, employees.last_name from employees&lt;br /&gt;
     -&amp;gt; left join projects on (employees.id=projects.employee_id) group by employees.id;&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 | project_num | first_name | last_name |&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 |           2 | John       | Doe       |&lt;br /&gt;
 |           0 | Keith      | Jones     |&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 2 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
(For more information on COUNT and GROUP BY, see [[#Aggregation Clauses|a later section]].)&lt;br /&gt;
&lt;br /&gt;
You can see that a LEFT JOIN preserves all rows from the &amp;quot;left&amp;quot; table in the join.  Likewise, a RIGHT JOIN preserves all rows from the &amp;quot;right&amp;quot; table.  A FULL JOIN preserves all rows from both tables.&lt;br /&gt;
&lt;br /&gt;
=== WHERE Clauses ===&lt;br /&gt;
&lt;br /&gt;
If you want to select data that satisfies a condition, use a '''WHERE''' clause.&lt;br /&gt;
&lt;br /&gt;
A simple '''WHERE''' clause can use equality, less than, greater than, and most other comparison operators.  For example, the following query selects all last names of employees with an Employee ID of less than 10:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	last_name&lt;br /&gt;
from employees&lt;br /&gt;
where&lt;br /&gt;
	employee_id &amp;lt; 10;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we wanted to select everyone from our employees table whose name started with a J, we could use a '''LIKE''' statement in our '''WHERE''' clause:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	first_name,&lt;br /&gt;
	last_name&lt;br /&gt;
from employees&lt;br /&gt;
where&lt;br /&gt;
	first_name like 'J%';&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The '''LIKE''' clause is SQL's way of letting you perform simple tests on strings.  (SQL's built-in string comparison operations are not as powerful as regular expressions, but they'll get the job done in most everyday situations.)&lt;br /&gt;
&lt;br /&gt;
=== Sorting Data ===&lt;br /&gt;
&lt;br /&gt;
You can sort data using an '''ORDER BY''' clause like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	first_name,&lt;br /&gt;
	last_name&lt;br /&gt;
from employees&lt;br /&gt;
order by last_name asc;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you wanted to select only the first few results from a query, use the '''LIMIT''' clause:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	first_name,&lt;br /&gt;
	last_name&lt;br /&gt;
from employees&lt;br /&gt;
order by last_name asc&lt;br /&gt;
limit 10;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is important to note that the ORDER BY on a field is performed ''after'' aggregation functions.  Currently, there is no way in MySQL to perform sorting ''before'' aggregation has occurred in a single query; we need to resort to nested queries.  (For example, in the baseball example below, it's not easy to select &amp;quot;the player from each team with the highest batting average&amp;quot;.  It's even harder, if not impossible, to select &amp;quot;the ''three'' players from each team with the highest batting averages&amp;quot;.)&lt;br /&gt;
&lt;br /&gt;
=== Aggregation Clauses ===&lt;br /&gt;
&lt;br /&gt;
When performing computations on an entire database, you will probably find yourself wanting to use ''aggregation functions''.  Aggregation functions include:&lt;br /&gt;
&lt;br /&gt;
* '''AVG(column_name)''' to compute the average value of column_name&lt;br /&gt;
* '''STD(column_name)''' to compute the standard deviation of column_name&lt;br /&gt;
* '''SUM(column_name)''' to compute the sum&lt;br /&gt;
* '''MIN(column_name)''' to find the minimum value&lt;br /&gt;
* '''MAX(column_name)''' to fund the maximum value&lt;br /&gt;
* '''COUNT(column_name)''' to count the total number of entries having a not null entry in column_name&lt;br /&gt;
&lt;br /&gt;
For example, if you had a table containing batter averages, you could calculate the mean batter average using this query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since WHERE clauses are performed ''before'' aggregation, you can also perform a query like&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players&lt;br /&gt;
where&lt;br /&gt;
	team_id=5;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to aggregate all rows that share a certain value in an index, use a '''GROUP BY''' clause.  For example, to select the average batter average for all teams, you could do&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players&lt;br /&gt;
group by team_id;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may find yourself wanting to apply a condition after the aggregation has occurred.  You can do this using a '''HAVING''' clause.  For example, the following query would select all baseball teams whose average batter average is more than 300:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players&lt;br /&gt;
group by team_id&lt;br /&gt;
having&lt;br /&gt;
	avg_batter_average &amp;gt; 300;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is perfectly valid to combine WHERE and HAVING clauses in a single query.  For example, the following query first finds all players whose first name starts with &amp;quot;J&amp;quot;, averages their batting averages together by team, and then selects those teams whose average batting average of the &amp;quot;J&amp;quot; players is more than 300; that is, it selects those teams &amp;quot;whose average batting average of players whose first name starts with J is more than 300&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players&lt;br /&gt;
where&lt;br /&gt;
	first_name like &amp;quot;J%&amp;quot;&lt;br /&gt;
group by team_id&lt;br /&gt;
having&lt;br /&gt;
	avg_batter_average &amp;gt; 300;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=MySQL_Schema_and_State&amp;diff=2850</id>
		<title>MySQL Schema and State</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=MySQL_Schema_and_State&amp;diff=2850"/>
		<updated>2023-01-10T06:04:42Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Syntax for Keys */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;MySQL is a powerful database that allows for complex logic when manipulating data.  This guide is an introduction and a reference to common SQL queries for schema and state manipulation.&lt;br /&gt;
&lt;br /&gt;
This guide assumes that you already have a working copy of MySQL.  If you don't, read [[Introduction to MySQL]] first.&lt;br /&gt;
&lt;br /&gt;
==Schema ==&lt;br /&gt;
&lt;br /&gt;
The ''schema'' of your database refers to the way that your data is structured and to how bits of data relate to each other.  Every database in your MySQL server has a separate schema, and separate databases should not typically interact with one another.&lt;br /&gt;
&lt;br /&gt;
=== Tables ===&lt;br /&gt;
&lt;br /&gt;
A database contains one or more ''tables''.  Tables contain columns and rows, which you may sometimes call ''fields'' and ''entries''.&lt;br /&gt;
&lt;br /&gt;
You can see all of the tables in the database using this query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
show tables;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you create a table, you should provide information about all of that table's columns within the ''create table'' query.  Here is the general syntax for the query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
create table &amp;lt;TABLENAME&amp;gt; (&lt;br /&gt;
	&amp;lt;FIELDNAME&amp;gt; &amp;lt;DATATYPE&amp;gt; &amp;lt;OPTIONS&amp;gt;,&lt;br /&gt;
	&amp;lt;FIELDNAME&amp;gt; &amp;lt;DATATYPE&amp;gt; &amp;lt;OPTIONS&amp;gt;,&lt;br /&gt;
	&amp;lt;FIELDNAME&amp;gt; &amp;lt;DATATYPE&amp;gt; &amp;lt;OPTIONS&amp;gt;,&lt;br /&gt;
	&amp;lt;FIELDNAME&amp;gt; &amp;lt;DATATYPE&amp;gt; &amp;lt;OPTIONS&amp;gt;&lt;br /&gt;
) &amp;lt;TABLE_OPTIONS&amp;gt;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can get details about an existing table using this query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
describe &amp;lt;TABLENAME&amp;gt;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Data Types ====&lt;br /&gt;
&lt;br /&gt;
Just like a programming language, MySQL has data types.  There are dozens of data types; some of the most common ones are documented below.&lt;br /&gt;
&lt;br /&gt;
===== String Data Types =====&lt;br /&gt;
&lt;br /&gt;
There are four main types of string data types: character, text, blob, and enumerable.&lt;br /&gt;
&lt;br /&gt;
* Character types are useful for short strings, like usernames and e-mail addresses.&lt;br /&gt;
* Text types differ from character types in that behind the scenes, they are not actually stored with the rest of the table row; they are useful for longer blocks of text, like forum posts.&lt;br /&gt;
* Blobs are for binary data, like files.&lt;br /&gt;
* Enumerables are for something that could have one of a set number of values (not more than 65535), like what State a user is from (Alabama, Alaska, and so on).  Enums are also useful for storing boolean data, like '''ENUM('yes','no')'''.  An enum is actually stored as an integer in the database, making queries more efficient.&lt;br /&gt;
&lt;br /&gt;
The syntax for these data types is:&lt;br /&gt;
&lt;br /&gt;
* '''VARCHAR(#)''', a string ''at most'' # characters long, where 0 ≤ # ≤ 65535&lt;br /&gt;
* '''CHAR(#)''', a string ''exactly'' # characters long, where 0 ≤ # ≤ 65535&lt;br /&gt;
* '''TINYTEXT''', a text block at most 255 characters long&lt;br /&gt;
* '''TEXT''', a text block at most 65535 characters long&lt;br /&gt;
* '''LONGTEXT''', a text block at most 4 GB in length&lt;br /&gt;
* '''BLOB''', a binary string at most 65 KB in length&lt;br /&gt;
* '''MEDIUMBLOB''', a binary string at most 16 MB in length&lt;br /&gt;
* '''LONGBLOB''', a binary string at most 4 GB in length&lt;br /&gt;
* '''ENUM('a', 'b', 'c')''', an enumerable with choices a, b, and c&lt;br /&gt;
&lt;br /&gt;
===== Numeric Data Types =====&lt;br /&gt;
&lt;br /&gt;
There are two types of numeric data types that you need to worry about: integers and decimals.  The difference between the two should be pretty self-explanatory.  The syntax for using these data types is:&lt;br /&gt;
&lt;br /&gt;
* '''TINYINT''', an integer ''n'' where -128 ≤ n ≤ 127&lt;br /&gt;
* '''TINYINT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 255&lt;br /&gt;
* '''SMALLINT''', an integer ''n'' where -32,768 ≤ n ≤ 32,767&lt;br /&gt;
* '''SMALLINT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 65,535&lt;br /&gt;
* '''MEDIUMINT''', an integer ''n'' where -8,388,608 ≤ n ≤ 8,388,607&lt;br /&gt;
* '''MEDIUMINT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 16,777,215&lt;br /&gt;
* '''INT''', an integer ''n'' where -2,147,483,648 ≤ n ≤ 2,147,483,647&lt;br /&gt;
* '''INT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 4,294,967,295&lt;br /&gt;
* '''BIGINT''', an integer ''n'' where -9,223,372,036,854,775,808 ≤ n ≤ 9,223,372,036,854,775,807&lt;br /&gt;
* '''BIGINT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 18,446,744,073,709,551,615&lt;br /&gt;
* '''DECIMAL(#a, #b)''', a decimal number at most ''#a'' digits long, ''#b'' of which are after the decimal point.  For example, ''DECIMAL(5,2)'' can contain ''n'' where -999.99 ≤ n ≤ 999.99&lt;br /&gt;
&lt;br /&gt;
When choosing the size of an integer, you should use the ''smallest integer for which you know you will never &amp;quot;run out of room&amp;quot;''.  In most everyday circumstances, '''MEDIUMINT''' should be the biggest you'll need.&lt;br /&gt;
&lt;br /&gt;
===== Temporal Data Types =====&lt;br /&gt;
{{XKCD&lt;br /&gt;
|name=2038&lt;br /&gt;
|id=607&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
MySQL provides a class of data types that specialize in handling dates and times.  The syntax for using date types is:&lt;br /&gt;
&lt;br /&gt;
* '''DATE''', a date ''d'' where &amp;lt;code&amp;gt;1000-01-01&amp;lt;/code&amp;gt; ≤ d ≤ &amp;lt;code&amp;gt;9999-12-31&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''DATETIME''', a date with time ''d'' where &amp;lt;code&amp;gt;1000-01-01 00:00:00&amp;lt;/code&amp;gt; ≤ d ≤ &amp;lt;code&amp;gt;9999-12-31 23:59:59&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''TIMESTAMP''', a date with time ''d'' where &amp;lt;code&amp;gt;1970-01-01 00:00:01 UTC&amp;lt;/code&amp;gt; ≤ d ≤ &amp;lt;code&amp;gt;2038-01-19 03:14:07 UTC&amp;lt;/code&amp;gt; (note: &amp;lt;code&amp;gt;1970-01-01 00:00:01 UTC&amp;lt;/code&amp;gt; is the Unix epoch)&lt;br /&gt;
* '''TIME''', a length of time ''t'' where &amp;lt;code&amp;gt;-838:59:59&amp;lt;/code&amp;gt; ≤ t ≤ &amp;lt;code&amp;gt;838:59:59&amp;lt;/code&amp;gt; (note: you cannot store time to a precision greater than 1 second)&lt;br /&gt;
* '''YEAR''', a year ''y'' where 1901 ≤ y ≤ 2155&lt;br /&gt;
&lt;br /&gt;
Note that '''TIMESTAMP''' is a highly versatile data type that can automatically change whenever a row is updated.  For more information, refer to [http://dev.mysql.com/doc/refman/5.6/en/timestamp-initialization.html the MySQL documentation].&lt;br /&gt;
&lt;br /&gt;
==== Field Options ====&lt;br /&gt;
&lt;br /&gt;
By default, any &amp;quot;cell&amp;quot; in a MySQL table can contain the ''NULL'' value.  If a certain field in your database schema will never contain a null value, you should declare it as '''NOT NULL''' in order to make queries more efficient.&lt;br /&gt;
&lt;br /&gt;
You can also specify a default value for a field.  If you do, when you insert data into the table, it won't be necessary to specify a value for that column.  To specify a default value for a field, use the syntax '''DEFAULT 'DEFAULT-VALUE' '''&lt;br /&gt;
&lt;br /&gt;
==== Create Table Example ====&lt;br /&gt;
&lt;br /&gt;
The following query would create a table called ''employees'' with six columns: employee ID, first name, last name, nickname, department, and the date that they joined the company.  Nickname is the only optional column.  The primary key for the table (see the next section) will be the ''id'' column.  The department will be one of five choices, with the default being CSE.  The storage engine for the table will be InnoDB, and the default charset for the table will be UTF8.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
create table employees (&lt;br /&gt;
	id mediumint unsigned not null auto_increment,&lt;br /&gt;
	first_name varchar(30) not null,&lt;br /&gt;
	last_name varchar(40) not null,&lt;br /&gt;
	nickname varchar(20),&lt;br /&gt;
	department enum('CSE','BME','EECE','ESE','MEMS') not null default 'CSE',&lt;br /&gt;
	joined timestamp not null default current_timestamp,&lt;br /&gt;
	primary key (id)&lt;br /&gt;
) engine = InnoDB default character set = utf8 collate = utf8_general_ci;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Keys ===&lt;br /&gt;
&lt;br /&gt;
When MySQL goes to get data out of a database, it does so using an index, like the index of a textbook.  In tech talk, we call indices ''keys''.&lt;br /&gt;
&lt;br /&gt;
==== Primary Key ====&lt;br /&gt;
&lt;br /&gt;
The '''primary key''' is what MySQL uses to distinguish one row from another.  Every table must have exactly one primary key; no more, no less.&lt;br /&gt;
&lt;br /&gt;
It is common practice to add a column to a table with data type '''mediumint unsigned not null auto_increment''' to serve as the primary key for a table.  The '''auto_increment''' is a neat little feature of MySQL that basically says, &amp;quot;when a new row is inserted into this table, assign it the next-lowest available ID&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
To specify a primary key for a table, use the syntax:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
primary key (column1, column2, column3)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unique Key ====&lt;br /&gt;
&lt;br /&gt;
If you want to specify that all items in a certain column will be unique from each other (like usernames or e-mail addresses), you can use a '''unique key'''.&lt;br /&gt;
&lt;br /&gt;
Because a table can have more than one unique key, you need to give your unique key a name.  It is common practice to name the key after the columns it is indexing, like ''idx_unique_column1_column2''.&lt;br /&gt;
&lt;br /&gt;
The syntax for specifying a unique key is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
unique key &amp;lt;INDEX_NAME&amp;gt; (&amp;lt;column1&amp;gt;, &amp;lt;column2&amp;gt;, &amp;lt;column3&amp;gt;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Foreign Key ====&lt;br /&gt;
&lt;br /&gt;
A '''foreign key''' is the most complicated type of MySQL index.  A foreign key says that the values in one column or columns are associated with the values in a column or columns in a ''different table''.&lt;br /&gt;
&lt;br /&gt;
For example, suppose you had two tables, one containing users and the other containing posts on a forum.  There is a one-to-many relationship between users and posts.  You could link a post to a user by having a column in your post table called ''user_id'', which would be a ''foreign key'' to the ''id'' column in your users table.&lt;br /&gt;
&lt;br /&gt;
Foreign keys can be a source of great confusion in developing database schemas.  If you get stuck, keep this tip in mind: '''Foreign Keys should always reference the columns used in the Primary Key of a different table.'''&lt;br /&gt;
&lt;br /&gt;
The syntax for creating a foreign key is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
foreign key (&amp;lt;column1&amp;gt;, &amp;lt;column2&amp;gt;, &amp;lt;column3&amp;gt;) references &amp;lt;FOREIGN_TABLENAME&amp;gt; (&amp;lt;column1&amp;gt;, &amp;lt;column2&amp;gt;, &amp;lt;column3&amp;gt;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, in the user-and-post example above, the foreign key declaration would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
foreign key (user_id) references user (id)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Further Reading about Foreign Keys =====&lt;br /&gt;
&lt;br /&gt;
* [[wikipedia:Foreign Key|Wikipedia Entry on Foreign Keys]]&lt;br /&gt;
* [http://www.techrepublic.com/article/an-introduction-to-foreign-keys-and-referential-integrity-in-mysql/6035435 An introductory article on Tech Republic]&lt;br /&gt;
* [http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html MySQL Documentation for Foreign Keys]&lt;br /&gt;
&lt;br /&gt;
==== Syntax for Keys ====&lt;br /&gt;
&lt;br /&gt;
You can define keys in your '''create table''' query, or you can define them later.&lt;br /&gt;
&lt;br /&gt;
If you define them in your '''create table''' query, do so after the column definitions but still inside the parentheses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
create table TABLENAME (&lt;br /&gt;
	column,&lt;br /&gt;
	column,&lt;br /&gt;
	....,&lt;br /&gt;
	primary key (column1, column2, ...),&lt;br /&gt;
	unique key INDEXNAME (column1, column2, ...),&lt;br /&gt;
	foreign key (column1, column2, ...) references FOREIGN_TABLENAME (column1, column2, ...)&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To define indices later, use an '''ALTER TABLE''' query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
alter table TABLENAME add unique key INDEXNAME (column1, column2, ...);&lt;br /&gt;
alter table TABLENAME add foreign key (column1, column2, ...) references FOREIGN_TABLENAME (column1, column2, ...);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== State ==&lt;br /&gt;
&lt;br /&gt;
The ''state'' of your database refers to the data that it holds.  Whenever you insert, update, or delete data, the state of your database changes.&lt;br /&gt;
&lt;br /&gt;
=== Inserting Data from a Query ===&lt;br /&gt;
&lt;br /&gt;
To insert a row (aka ''entry'') into a table, use a query of the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
insert into TABLENAME (column1, column2, column3) values (value1_1, value2_1, value3_1), (value1_2, value2_2, value3_2), ...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, to insert an employee into the table we created earlier, you could use the query&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
insert into employees (first_name, last_name, department) values ('John', 'Doe', 'BME'), ('Keith', 'Jones', 'ESE');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because of the various default and auto_increment values we have specified in our database, the database would now contain the following data:&lt;br /&gt;
&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 | id | first_name | last_name | nickname | department | joined              |&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 |  1 | John       | Doe       | NULL     | BME        | 2012-08-22 22:02:24 |&lt;br /&gt;
 |  2 | Keith      | Jones     | NULL     | ESE        | 2012-08-22 22:02:24 |&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
&lt;br /&gt;
If you want to insert a DATE or DATETIME value into a database, use the YYYY-MM-DD HH:MM:SS format.  The exception is with TIMESTAMP, in which you should use a 16-bit integer representing the number of seconds since January 1, 1970.&lt;br /&gt;
&lt;br /&gt;
=== Inserting Data from a File ===&lt;br /&gt;
&lt;br /&gt;
The '''load data infile''' command populates a table using data stored in a text file. The general form of the command is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
LOAD DATA INFILE 'dataFile.txt' INTO TABLE table_name;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where ''dataFile.txt'' is located relative to the server's data directory if a path name with leading components is given; otherwise, if no leading components are given, the server assumes the file is in the default database's database directory.  If an absolute path is specified, the server uses it. For this command to work, you must issue the following command to grant the FILE privilege to your user:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
GRANT FILE on *.* to 'user'@'host';&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, and quite usefully, you can load data from a local file (a file residing on the same machine as the client) using the LOCAL keyword. When loading data from the local machine you do not need to grant your user the FILE privilege, think about why this might be the case.  (Hint: what is going on behind the scenes when you load the data in from a local machine when your database is hosted on a different machine?)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
LOAD DATA LOCAL INFILE '/home/linus_torvalds/Documents/dataFile.txt' INTO TABLE table_name;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' When the local keyword is used, it is best to specify an absolute path.&lt;br /&gt;
&lt;br /&gt;
'''Additional Note:'''  If we SSH into our EC2 instance and then run the mysql command, the client is the EC2 instance, not the local computer that we SSH from. The LOCAL keyword in this case is allowing us to load files from the EC2 instance, not the local computer that we are using.&lt;br /&gt;
&lt;br /&gt;
By default, the text files are assumed to have tab-delimited columns with column values specified in the same order as they are defined in the table (though you can specify additional/alternative delimiters using additional options).&lt;br /&gt;
&lt;br /&gt;
=== Updating Data ===&lt;br /&gt;
&lt;br /&gt;
To update a row in a table, use a query of the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
update TABLENAME set column1=value1, column2=value2, column3=value3 where CONDITION&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, to set Keith Jones's nickname to &amp;quot;KJ&amp;quot;, you would run the query&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
update employees set nickname='KJ' where id=2;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deleting Data ===&lt;br /&gt;
&lt;br /&gt;
To delete a row from a table, use a query of the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
delete from TABLENAME where CONDITION&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, to delete John Doe from the table, you would run the query&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
delete from employees where id=1;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''DO NOT FORGET THE WHERE CLAUSE!'''  If you do, ''all'' rows will be deleted from your table!&lt;br /&gt;
&lt;br /&gt;
== Selecting Data ==&lt;br /&gt;
&lt;br /&gt;
The most simple query to select data from a table is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select * from TABLENAME;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, in practice, you will almost always want to perform a more advanced query.&lt;br /&gt;
&lt;br /&gt;
=== Selecting Specific Columns ===&lt;br /&gt;
&lt;br /&gt;
In order to save transmission time, you should select only those columns that you need in your application.  The syntax for selecting only certain columns is&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select column1, column2, column3 from TABLENAME;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computation ===&lt;br /&gt;
&lt;br /&gt;
MySQL can perform computation.  For example, if you wanted to select the amount of time that a certain employee has been at the company, you could run the query&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select TIMESTAMPDIFF( second, joined, NOW() ) as time_with_company from employees;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Joins ===&lt;br /&gt;
&lt;br /&gt;
When you have one-to-one, one-to-many, or many-to-many relationships between tables, you will often want to select data from multiple tables in one query.  To do this, use '''joins'''.&lt;br /&gt;
&lt;br /&gt;
Joins are best described by example.  Suppose you had the following tables in a MySQL database:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; describe employees;&lt;br /&gt;
 +------------+---------------------------------------+------+-----+-------------------+----------------+&lt;br /&gt;
 | Field      | Type                                  | Null | Key | Default           | Extra          |&lt;br /&gt;
 +------------+---------------------------------------+------+-----+-------------------+----------------+&lt;br /&gt;
 | id         | mediumint(8) unsigned                 | NO   | PRI | NULL              | auto_increment |&lt;br /&gt;
 | first_name | varchar(30)                           | NO   |     | NULL              |                |&lt;br /&gt;
 | last_name  | varchar(40)                           | NO   |     | NULL              |                |&lt;br /&gt;
 | nickname   | varchar(20)                           | YES  |     | NULL              |                |&lt;br /&gt;
 | department | enum('CSE','BME','EECE','ESE','MEMS') | NO   |     | CSE               |                |&lt;br /&gt;
 | joined     | timestamp                             | NO   |     | CURRENT_TIMESTAMP |                |&lt;br /&gt;
 +------------+---------------------------------------+------+-----+-------------------+----------------+&lt;br /&gt;
 6 rows in set (0.00 sec)&lt;br /&gt;
 &lt;br /&gt;
 mysql&amp;gt; describe projects;&lt;br /&gt;
 +--------------+-----------------------+------+-----+---------+----------------+&lt;br /&gt;
 | Field        | Type                  | Null | Key | Default | Extra          |&lt;br /&gt;
 +--------------+-----------------------+------+-----+---------+----------------+&lt;br /&gt;
 | id           | mediumint(8) unsigned | NO   | PRI | NULL    | auto_increment |&lt;br /&gt;
 | employee_id  | mediumint(8) unsigned | NO   | MUL | NULL    |                |&lt;br /&gt;
 | project_name | tinytext              | NO   |     | NULL    |                |&lt;br /&gt;
 +--------------+-----------------------+------+-----+---------+----------------+&lt;br /&gt;
 3 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
Further, suppose the tables had the following data:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select * from employees;&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 | id | first_name | last_name | nickname | department | joined              |&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 |  1 | John       | Doe       | NULL     | BME        | 2012-08-22 22:02:24 |&lt;br /&gt;
 |  2 | Keith      | Jones     | KK       | ESE        | 2012-08-22 22:02:24 |&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 2 rows in set (0.00 sec)&lt;br /&gt;
 &lt;br /&gt;
 mysql&amp;gt; select * from projects;&lt;br /&gt;
 +----+-------------+-----------------------------------+&lt;br /&gt;
 | id | employee_id | project_name                      |&lt;br /&gt;
 +----+-------------+-----------------------------------+&lt;br /&gt;
 |  1 |           1 | Interview the Chancellor          |&lt;br /&gt;
 |  2 |           1 | Give Presentation in Mumbai       |&lt;br /&gt;
 |  3 |           2 | Publish Research Paper in Journal |&lt;br /&gt;
 +----+-------------+-----------------------------------+&lt;br /&gt;
 3 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
If you ran the following query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	project_name,&lt;br /&gt;
	employees.first_name,&lt;br /&gt;
	employees.last_name&lt;br /&gt;
from projects&lt;br /&gt;
	join employees on (projects.employee_id=employees.id);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You would get the result:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select project_name, employees.first_name, employees.last_name from projects&lt;br /&gt;
     -&amp;gt; join employees on (projects.employee_id=employees.id);&lt;br /&gt;
 +-----------------------------------+------------+-----------+&lt;br /&gt;
 | project_name                      | first_name | last_name |&lt;br /&gt;
 +-----------------------------------+------------+-----------+&lt;br /&gt;
 | Interview the Chancellor          | John       | Doe       |&lt;br /&gt;
 | Give Presentation in Mumbai       | John       | Doe       |&lt;br /&gt;
 | Publish Research Paper in Journal | Keith      | Jones     |&lt;br /&gt;
 +-----------------------------------+------------+-----------+&lt;br /&gt;
 3 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
Isn't that cool?&lt;br /&gt;
&lt;br /&gt;
==== Inner Joins, Left Joins, Right Joins, and Full Joins ====&lt;br /&gt;
&lt;br /&gt;
When you perform a '''JOIN''' like we did above, you are implicitly performing an '''INNER JOIN'''.  However, there may be times when you want to select data in a query even if it doesn't have a complement in the joined table.  For example, suppose Keith Jones cancelled his project.  The projects table now contains the following data:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select * from projects;&lt;br /&gt;
 +----+-------------+-----------------------------+&lt;br /&gt;
 | id | employee_id | project_name                |&lt;br /&gt;
 +----+-------------+-----------------------------+&lt;br /&gt;
 |  1 |           1 | Interview the Chancellor    |&lt;br /&gt;
 |  2 |           1 | Give Presentation in Mumbai |&lt;br /&gt;
 +----+-------------+-----------------------------+&lt;br /&gt;
 2 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
Now, we could run the following query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	count(projects.id) as project_num,&lt;br /&gt;
	employees.first_name,&lt;br /&gt;
	employees.last_name&lt;br /&gt;
from employees&lt;br /&gt;
	join projects on (employees.id=projects.employee_id)&lt;br /&gt;
group by employees.id;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We get the result:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select count(projects.id) as project_num, employees.first_name, employees.last_name from employees&lt;br /&gt;
     -&amp;gt; join projects on (employees.id=projects.employee_id) group by employees.id;&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 | project_num | first_name | last_name |&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 |           2 | John       | Doe       |&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 1 row in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
But where's Keith Jones?  Since Keith Jones didn't have any projects, he was omitted from the result.  This is probably not what we intended to happen.  Instead, you should perform a '''LEFT JOIN''', like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	count(projects.id) as project_num,&lt;br /&gt;
	employees.first_name,&lt;br /&gt;
	employees.last_name&lt;br /&gt;
from employees&lt;br /&gt;
	left join projects on (employees.id=projects.employee_id)&lt;br /&gt;
group by employees.id;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result will now be:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select count(projects.id) as project_num, employees.first_name, employees.last_name from employees&lt;br /&gt;
     -&amp;gt; left join projects on (employees.id=projects.employee_id) group by employees.id;&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 | project_num | first_name | last_name |&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 |           2 | John       | Doe       |&lt;br /&gt;
 |           0 | Keith      | Jones     |&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 2 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
(For more information on COUNT and GROUP BY, see [[#Aggregation Clauses|a later section]].)&lt;br /&gt;
&lt;br /&gt;
You can see that a LEFT JOIN preserves all rows from the &amp;quot;left&amp;quot; table in the join.  Likewise, a RIGHT JOIN preserves all rows from the &amp;quot;right&amp;quot; table.  A FULL JOIN preserves all rows from both tables.&lt;br /&gt;
&lt;br /&gt;
=== WHERE Clauses ===&lt;br /&gt;
&lt;br /&gt;
If you want to select data that satisfies a condition, use a '''WHERE''' clause.&lt;br /&gt;
&lt;br /&gt;
A simple '''WHERE''' clause can use equality, less than, greater than, and most other comparison operators.  For example, the following query selects all last names of employees with an Employee ID of less than 10:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	last_name&lt;br /&gt;
from employees&lt;br /&gt;
where&lt;br /&gt;
	employee_id &amp;lt; 10;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we wanted to select everyone from our employees table whose name started with a J, we could use a '''LIKE''' statement in our '''WHERE''' clause:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	first_name,&lt;br /&gt;
	last_name&lt;br /&gt;
from employees&lt;br /&gt;
where&lt;br /&gt;
	first_name like 'J%';&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The '''LIKE''' clause is SQL's way of letting you perform simple tests on strings.  (SQL's built-in string comparison operations are not as powerful as regular expressions, but they'll get the job done in most everyday situations.)&lt;br /&gt;
&lt;br /&gt;
=== Sorting Data ===&lt;br /&gt;
&lt;br /&gt;
You can sort data using an '''ORDER BY''' clause like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	first_name,&lt;br /&gt;
	last_name&lt;br /&gt;
from employees&lt;br /&gt;
order by last_name asc;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you wanted to select only the first few results from a query, use the '''LIMIT''' clause:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	first_name,&lt;br /&gt;
	last_name&lt;br /&gt;
from employees&lt;br /&gt;
order by last_name asc&lt;br /&gt;
limit 10;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is important to note that the ORDER BY on a field is performed ''after'' aggregation functions.  Currently, there is no way in MySQL to perform sorting ''before'' aggregation has occurred in a single query; we need to resort to nested queries.  (For example, in the baseball example below, it's not easy to select &amp;quot;the player from each team with the highest batting average&amp;quot;.  It's even harder, if not impossible, to select &amp;quot;the ''three'' players from each team with the highest batting averages&amp;quot;.)&lt;br /&gt;
&lt;br /&gt;
=== Aggregation Clauses ===&lt;br /&gt;
&lt;br /&gt;
When performing computations on an entire database, you will probably find yourself wanting to use ''aggregation functions''.  Aggregation functions include:&lt;br /&gt;
&lt;br /&gt;
* '''AVG(column_name)''' to compute the average value of column_name&lt;br /&gt;
* '''STD(column_name)''' to compute the standard deviation of column_name&lt;br /&gt;
* '''SUM(column_name)''' to compute the sum&lt;br /&gt;
* '''MIN(column_name)''' to find the minimum value&lt;br /&gt;
* '''MAX(column_name)''' to fund the maximum value&lt;br /&gt;
* '''COUNT(column_name)''' to count the total number of entries having a not null entry in column_name&lt;br /&gt;
&lt;br /&gt;
For example, if you had a table containing batter averages, you could calculate the mean batter average using this query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since WHERE clauses are performed ''before'' aggregation, you can also perform a query like&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players&lt;br /&gt;
where&lt;br /&gt;
	team_id=5;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to aggregate all rows that share a certain value in an index, use a '''GROUP BY''' clause.  For example, to select the average batter average for all teams, you could do&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players&lt;br /&gt;
group by team_id;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may find yourself wanting to apply a condition after the aggregation has occurred.  You can do this using a '''HAVING''' clause.  For example, the following query would select all baseball teams whose average batter average is more than 300:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players&lt;br /&gt;
group by team_id&lt;br /&gt;
having&lt;br /&gt;
	avg_batter_average &amp;gt; 300;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is perfectly valid to combine WHERE and HAVING clauses in a single query.  For example, the following query first finds all players whose first name starts with &amp;quot;J&amp;quot;, averages their batting averages together by team, and then selects those teams whose average batting average of the &amp;quot;J&amp;quot; players is more than 300; that is, it selects those teams &amp;quot;whose average batting average of players whose first name starts with J is more than 300&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players&lt;br /&gt;
where&lt;br /&gt;
	first_name like &amp;quot;J%&amp;quot;&lt;br /&gt;
group by team_id&lt;br /&gt;
having&lt;br /&gt;
	avg_batter_average &amp;gt; 300;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=MySQL_Schema_and_State&amp;diff=2849</id>
		<title>MySQL Schema and State</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=MySQL_Schema_and_State&amp;diff=2849"/>
		<updated>2023-01-10T06:02:51Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Syntax for Keys */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;MySQL is a powerful database that allows for complex logic when manipulating data.  This guide is an introduction and a reference to common SQL queries for schema and state manipulation.&lt;br /&gt;
&lt;br /&gt;
This guide assumes that you already have a working copy of MySQL.  If you don't, read [[Introduction to MySQL]] first.&lt;br /&gt;
&lt;br /&gt;
==Schema ==&lt;br /&gt;
&lt;br /&gt;
The ''schema'' of your database refers to the way that your data is structured and to how bits of data relate to each other.  Every database in your MySQL server has a separate schema, and separate databases should not typically interact with one another.&lt;br /&gt;
&lt;br /&gt;
=== Tables ===&lt;br /&gt;
&lt;br /&gt;
A database contains one or more ''tables''.  Tables contain columns and rows, which you may sometimes call ''fields'' and ''entries''.&lt;br /&gt;
&lt;br /&gt;
You can see all of the tables in the database using this query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
show tables;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you create a table, you should provide information about all of that table's columns within the ''create table'' query.  Here is the general syntax for the query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
create table &amp;lt;TABLENAME&amp;gt; (&lt;br /&gt;
	&amp;lt;FIELDNAME&amp;gt; &amp;lt;DATATYPE&amp;gt; &amp;lt;OPTIONS&amp;gt;,&lt;br /&gt;
	&amp;lt;FIELDNAME&amp;gt; &amp;lt;DATATYPE&amp;gt; &amp;lt;OPTIONS&amp;gt;,&lt;br /&gt;
	&amp;lt;FIELDNAME&amp;gt; &amp;lt;DATATYPE&amp;gt; &amp;lt;OPTIONS&amp;gt;,&lt;br /&gt;
	&amp;lt;FIELDNAME&amp;gt; &amp;lt;DATATYPE&amp;gt; &amp;lt;OPTIONS&amp;gt;&lt;br /&gt;
) &amp;lt;TABLE_OPTIONS&amp;gt;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can get details about an existing table using this query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
describe &amp;lt;TABLENAME&amp;gt;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Data Types ====&lt;br /&gt;
&lt;br /&gt;
Just like a programming language, MySQL has data types.  There are dozens of data types; some of the most common ones are documented below.&lt;br /&gt;
&lt;br /&gt;
===== String Data Types =====&lt;br /&gt;
&lt;br /&gt;
There are four main types of string data types: character, text, blob, and enumerable.&lt;br /&gt;
&lt;br /&gt;
* Character types are useful for short strings, like usernames and e-mail addresses.&lt;br /&gt;
* Text types differ from character types in that behind the scenes, they are not actually stored with the rest of the table row; they are useful for longer blocks of text, like forum posts.&lt;br /&gt;
* Blobs are for binary data, like files.&lt;br /&gt;
* Enumerables are for something that could have one of a set number of values (not more than 65535), like what State a user is from (Alabama, Alaska, and so on).  Enums are also useful for storing boolean data, like '''ENUM('yes','no')'''.  An enum is actually stored as an integer in the database, making queries more efficient.&lt;br /&gt;
&lt;br /&gt;
The syntax for these data types is:&lt;br /&gt;
&lt;br /&gt;
* '''VARCHAR(#)''', a string ''at most'' # characters long, where 0 ≤ # ≤ 65535&lt;br /&gt;
* '''CHAR(#)''', a string ''exactly'' # characters long, where 0 ≤ # ≤ 65535&lt;br /&gt;
* '''TINYTEXT''', a text block at most 255 characters long&lt;br /&gt;
* '''TEXT''', a text block at most 65535 characters long&lt;br /&gt;
* '''LONGTEXT''', a text block at most 4 GB in length&lt;br /&gt;
* '''BLOB''', a binary string at most 65 KB in length&lt;br /&gt;
* '''MEDIUMBLOB''', a binary string at most 16 MB in length&lt;br /&gt;
* '''LONGBLOB''', a binary string at most 4 GB in length&lt;br /&gt;
* '''ENUM('a', 'b', 'c')''', an enumerable with choices a, b, and c&lt;br /&gt;
&lt;br /&gt;
===== Numeric Data Types =====&lt;br /&gt;
&lt;br /&gt;
There are two types of numeric data types that you need to worry about: integers and decimals.  The difference between the two should be pretty self-explanatory.  The syntax for using these data types is:&lt;br /&gt;
&lt;br /&gt;
* '''TINYINT''', an integer ''n'' where -128 ≤ n ≤ 127&lt;br /&gt;
* '''TINYINT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 255&lt;br /&gt;
* '''SMALLINT''', an integer ''n'' where -32,768 ≤ n ≤ 32,767&lt;br /&gt;
* '''SMALLINT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 65,535&lt;br /&gt;
* '''MEDIUMINT''', an integer ''n'' where -8,388,608 ≤ n ≤ 8,388,607&lt;br /&gt;
* '''MEDIUMINT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 16,777,215&lt;br /&gt;
* '''INT''', an integer ''n'' where -2,147,483,648 ≤ n ≤ 2,147,483,647&lt;br /&gt;
* '''INT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 4,294,967,295&lt;br /&gt;
* '''BIGINT''', an integer ''n'' where -9,223,372,036,854,775,808 ≤ n ≤ 9,223,372,036,854,775,807&lt;br /&gt;
* '''BIGINT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 18,446,744,073,709,551,615&lt;br /&gt;
* '''DECIMAL(#a, #b)''', a decimal number at most ''#a'' digits long, ''#b'' of which are after the decimal point.  For example, ''DECIMAL(5,2)'' can contain ''n'' where -999.99 ≤ n ≤ 999.99&lt;br /&gt;
&lt;br /&gt;
When choosing the size of an integer, you should use the ''smallest integer for which you know you will never &amp;quot;run out of room&amp;quot;''.  In most everyday circumstances, '''MEDIUMINT''' should be the biggest you'll need.&lt;br /&gt;
&lt;br /&gt;
===== Temporal Data Types =====&lt;br /&gt;
{{XKCD&lt;br /&gt;
|name=2038&lt;br /&gt;
|id=607&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
MySQL provides a class of data types that specialize in handling dates and times.  The syntax for using date types is:&lt;br /&gt;
&lt;br /&gt;
* '''DATE''', a date ''d'' where &amp;lt;code&amp;gt;1000-01-01&amp;lt;/code&amp;gt; ≤ d ≤ &amp;lt;code&amp;gt;9999-12-31&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''DATETIME''', a date with time ''d'' where &amp;lt;code&amp;gt;1000-01-01 00:00:00&amp;lt;/code&amp;gt; ≤ d ≤ &amp;lt;code&amp;gt;9999-12-31 23:59:59&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''TIMESTAMP''', a date with time ''d'' where &amp;lt;code&amp;gt;1970-01-01 00:00:01 UTC&amp;lt;/code&amp;gt; ≤ d ≤ &amp;lt;code&amp;gt;2038-01-19 03:14:07 UTC&amp;lt;/code&amp;gt; (note: &amp;lt;code&amp;gt;1970-01-01 00:00:01 UTC&amp;lt;/code&amp;gt; is the Unix epoch)&lt;br /&gt;
* '''TIME''', a length of time ''t'' where &amp;lt;code&amp;gt;-838:59:59&amp;lt;/code&amp;gt; ≤ t ≤ &amp;lt;code&amp;gt;838:59:59&amp;lt;/code&amp;gt; (note: you cannot store time to a precision greater than 1 second)&lt;br /&gt;
* '''YEAR''', a year ''y'' where 1901 ≤ y ≤ 2155&lt;br /&gt;
&lt;br /&gt;
Note that '''TIMESTAMP''' is a highly versatile data type that can automatically change whenever a row is updated.  For more information, refer to [http://dev.mysql.com/doc/refman/5.6/en/timestamp-initialization.html the MySQL documentation].&lt;br /&gt;
&lt;br /&gt;
==== Field Options ====&lt;br /&gt;
&lt;br /&gt;
By default, any &amp;quot;cell&amp;quot; in a MySQL table can contain the ''NULL'' value.  If a certain field in your database schema will never contain a null value, you should declare it as '''NOT NULL''' in order to make queries more efficient.&lt;br /&gt;
&lt;br /&gt;
You can also specify a default value for a field.  If you do, when you insert data into the table, it won't be necessary to specify a value for that column.  To specify a default value for a field, use the syntax '''DEFAULT 'DEFAULT-VALUE' '''&lt;br /&gt;
&lt;br /&gt;
==== Create Table Example ====&lt;br /&gt;
&lt;br /&gt;
The following query would create a table called ''employees'' with six columns: employee ID, first name, last name, nickname, department, and the date that they joined the company.  Nickname is the only optional column.  The primary key for the table (see the next section) will be the ''id'' column.  The department will be one of five choices, with the default being CSE.  The storage engine for the table will be InnoDB, and the default charset for the table will be UTF8.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
create table employees (&lt;br /&gt;
	id mediumint unsigned not null auto_increment,&lt;br /&gt;
	first_name varchar(30) not null,&lt;br /&gt;
	last_name varchar(40) not null,&lt;br /&gt;
	nickname varchar(20),&lt;br /&gt;
	department enum('CSE','BME','EECE','ESE','MEMS') not null default 'CSE',&lt;br /&gt;
	joined timestamp not null default current_timestamp,&lt;br /&gt;
	primary key (id)&lt;br /&gt;
) engine = InnoDB default character set = utf8 collate = utf8_general_ci;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Keys ===&lt;br /&gt;
&lt;br /&gt;
When MySQL goes to get data out of a database, it does so using an index, like the index of a textbook.  In tech talk, we call indices ''keys''.&lt;br /&gt;
&lt;br /&gt;
==== Primary Key ====&lt;br /&gt;
&lt;br /&gt;
The '''primary key''' is what MySQL uses to distinguish one row from another.  Every table must have exactly one primary key; no more, no less.&lt;br /&gt;
&lt;br /&gt;
It is common practice to add a column to a table with data type '''mediumint unsigned not null auto_increment''' to serve as the primary key for a table.  The '''auto_increment''' is a neat little feature of MySQL that basically says, &amp;quot;when a new row is inserted into this table, assign it the next-lowest available ID&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
To specify a primary key for a table, use the syntax:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
primary key (column1, column2, column3)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unique Key ====&lt;br /&gt;
&lt;br /&gt;
If you want to specify that all items in a certain column will be unique from each other (like usernames or e-mail addresses), you can use a '''unique key'''.&lt;br /&gt;
&lt;br /&gt;
Because a table can have more than one unique key, you need to give your unique key a name.  It is common practice to name the key after the columns it is indexing, like ''idx_unique_column1_column2''.&lt;br /&gt;
&lt;br /&gt;
The syntax for specifying a unique key is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
unique key &amp;lt;INDEX_NAME&amp;gt; (&amp;lt;column1&amp;gt;, &amp;lt;column2&amp;gt;, &amp;lt;column3&amp;gt;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Foreign Key ====&lt;br /&gt;
&lt;br /&gt;
A '''foreign key''' is the most complicated type of MySQL index.  A foreign key says that the values in one column or columns are associated with the values in a column or columns in a ''different table''.&lt;br /&gt;
&lt;br /&gt;
For example, suppose you had two tables, one containing users and the other containing posts on a forum.  There is a one-to-many relationship between users and posts.  You could link a post to a user by having a column in your post table called ''user_id'', which would be a ''foreign key'' to the ''id'' column in your users table.&lt;br /&gt;
&lt;br /&gt;
Foreign keys can be a source of great confusion in developing database schemas.  If you get stuck, keep this tip in mind: '''Foreign Keys should always reference the columns used in the Primary Key of a different table.'''&lt;br /&gt;
&lt;br /&gt;
The syntax for creating a foreign key is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
foreign key (&amp;lt;column1&amp;gt;, &amp;lt;column2&amp;gt;, &amp;lt;column3&amp;gt;) references &amp;lt;FOREIGN_TABLENAME&amp;gt; (&amp;lt;column1&amp;gt;, &amp;lt;column2&amp;gt;, &amp;lt;column3&amp;gt;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, in the user-and-post example above, the foreign key declaration would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
foreign key (user_id) references user (id)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Further Reading about Foreign Keys =====&lt;br /&gt;
&lt;br /&gt;
* [[wikipedia:Foreign Key|Wikipedia Entry on Foreign Keys]]&lt;br /&gt;
* [http://www.techrepublic.com/article/an-introduction-to-foreign-keys-and-referential-integrity-in-mysql/6035435 An introductory article on Tech Republic]&lt;br /&gt;
* [http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html MySQL Documentation for Foreign Keys]&lt;br /&gt;
&lt;br /&gt;
==== Syntax for Keys ====&lt;br /&gt;
&lt;br /&gt;
You can define keys in your '''create table''' query, or you can define them later.&lt;br /&gt;
&lt;br /&gt;
If you define them in your '''create table''' query, do so after the column definitions but still inside the parentheses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
create table &amp;lt;TABLENAME&amp;gt; (&lt;br /&gt;
	&amp;lt;column&amp;gt;,&lt;br /&gt;
	&amp;lt;column&amp;gt;,&lt;br /&gt;
	....,&lt;br /&gt;
	primary key (&amp;lt;column1&amp;gt;, &amp;lt;column2&amp;gt;, ...),&lt;br /&gt;
	unique key &amp;lt;INDEXNAME&amp;gt; (&amp;lt;column1&amp;gt;, &amp;lt;column2&amp;gt;, ...),&lt;br /&gt;
	foreign key (&amp;lt;column1&amp;gt;, &amp;lt;column2&amp;gt;, ...) references &amp;lt;FOREIGN_TABLENAME&amp;gt; (&amp;lt;column1&amp;gt;, &amp;lt;column2&amp;gt;, ...)&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To define indices later, use an '''ALTER TABLE''' query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
alter table &amp;lt;TABLENAME&amp;gt; add unique key &amp;lt;INDEXNAME&amp;gt; (&amp;lt;column1&amp;gt;, &amp;lt;column2&amp;gt;, ...);&lt;br /&gt;
alter table &amp;lt;TABLENAME&amp;gt; add foreign key (&amp;lt;column1&amp;gt;, &amp;lt;column2&amp;gt;, ...) references &amp;lt;FOREIGN_TABLENAME&amp;gt; (&amp;lt;column1&amp;gt;, &amp;lt;column2&amp;gt;, ...);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== State ==&lt;br /&gt;
&lt;br /&gt;
The ''state'' of your database refers to the data that it holds.  Whenever you insert, update, or delete data, the state of your database changes.&lt;br /&gt;
&lt;br /&gt;
=== Inserting Data from a Query ===&lt;br /&gt;
&lt;br /&gt;
To insert a row (aka ''entry'') into a table, use a query of the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
insert into TABLENAME (column1, column2, column3) values (value1_1, value2_1, value3_1), (value1_2, value2_2, value3_2), ...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, to insert an employee into the table we created earlier, you could use the query&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
insert into employees (first_name, last_name, department) values ('John', 'Doe', 'BME'), ('Keith', 'Jones', 'ESE');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because of the various default and auto_increment values we have specified in our database, the database would now contain the following data:&lt;br /&gt;
&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 | id | first_name | last_name | nickname | department | joined              |&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 |  1 | John       | Doe       | NULL     | BME        | 2012-08-22 22:02:24 |&lt;br /&gt;
 |  2 | Keith      | Jones     | NULL     | ESE        | 2012-08-22 22:02:24 |&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
&lt;br /&gt;
If you want to insert a DATE or DATETIME value into a database, use the YYYY-MM-DD HH:MM:SS format.  The exception is with TIMESTAMP, in which you should use a 16-bit integer representing the number of seconds since January 1, 1970.&lt;br /&gt;
&lt;br /&gt;
=== Inserting Data from a File ===&lt;br /&gt;
&lt;br /&gt;
The '''load data infile''' command populates a table using data stored in a text file. The general form of the command is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
LOAD DATA INFILE 'dataFile.txt' INTO TABLE table_name;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where ''dataFile.txt'' is located relative to the server's data directory if a path name with leading components is given; otherwise, if no leading components are given, the server assumes the file is in the default database's database directory.  If an absolute path is specified, the server uses it. For this command to work, you must issue the following command to grant the FILE privilege to your user:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
GRANT FILE on *.* to 'user'@'host';&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, and quite usefully, you can load data from a local file (a file residing on the same machine as the client) using the LOCAL keyword. When loading data from the local machine you do not need to grant your user the FILE privilege, think about why this might be the case.  (Hint: what is going on behind the scenes when you load the data in from a local machine when your database is hosted on a different machine?)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
LOAD DATA LOCAL INFILE '/home/linus_torvalds/Documents/dataFile.txt' INTO TABLE table_name;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' When the local keyword is used, it is best to specify an absolute path.&lt;br /&gt;
&lt;br /&gt;
'''Additional Note:'''  If we SSH into our EC2 instance and then run the mysql command, the client is the EC2 instance, not the local computer that we SSH from. The LOCAL keyword in this case is allowing us to load files from the EC2 instance, not the local computer that we are using.&lt;br /&gt;
&lt;br /&gt;
By default, the text files are assumed to have tab-delimited columns with column values specified in the same order as they are defined in the table (though you can specify additional/alternative delimiters using additional options).&lt;br /&gt;
&lt;br /&gt;
=== Updating Data ===&lt;br /&gt;
&lt;br /&gt;
To update a row in a table, use a query of the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
update TABLENAME set column1=value1, column2=value2, column3=value3 where CONDITION&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, to set Keith Jones's nickname to &amp;quot;KJ&amp;quot;, you would run the query&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
update employees set nickname='KJ' where id=2;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deleting Data ===&lt;br /&gt;
&lt;br /&gt;
To delete a row from a table, use a query of the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
delete from TABLENAME where CONDITION&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, to delete John Doe from the table, you would run the query&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
delete from employees where id=1;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''DO NOT FORGET THE WHERE CLAUSE!'''  If you do, ''all'' rows will be deleted from your table!&lt;br /&gt;
&lt;br /&gt;
== Selecting Data ==&lt;br /&gt;
&lt;br /&gt;
The most simple query to select data from a table is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select * from TABLENAME;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, in practice, you will almost always want to perform a more advanced query.&lt;br /&gt;
&lt;br /&gt;
=== Selecting Specific Columns ===&lt;br /&gt;
&lt;br /&gt;
In order to save transmission time, you should select only those columns that you need in your application.  The syntax for selecting only certain columns is&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select column1, column2, column3 from TABLENAME;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computation ===&lt;br /&gt;
&lt;br /&gt;
MySQL can perform computation.  For example, if you wanted to select the amount of time that a certain employee has been at the company, you could run the query&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select TIMESTAMPDIFF( second, joined, NOW() ) as time_with_company from employees;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Joins ===&lt;br /&gt;
&lt;br /&gt;
When you have one-to-one, one-to-many, or many-to-many relationships between tables, you will often want to select data from multiple tables in one query.  To do this, use '''joins'''.&lt;br /&gt;
&lt;br /&gt;
Joins are best described by example.  Suppose you had the following tables in a MySQL database:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; describe employees;&lt;br /&gt;
 +------------+---------------------------------------+------+-----+-------------------+----------------+&lt;br /&gt;
 | Field      | Type                                  | Null | Key | Default           | Extra          |&lt;br /&gt;
 +------------+---------------------------------------+------+-----+-------------------+----------------+&lt;br /&gt;
 | id         | mediumint(8) unsigned                 | NO   | PRI | NULL              | auto_increment |&lt;br /&gt;
 | first_name | varchar(30)                           | NO   |     | NULL              |                |&lt;br /&gt;
 | last_name  | varchar(40)                           | NO   |     | NULL              |                |&lt;br /&gt;
 | nickname   | varchar(20)                           | YES  |     | NULL              |                |&lt;br /&gt;
 | department | enum('CSE','BME','EECE','ESE','MEMS') | NO   |     | CSE               |                |&lt;br /&gt;
 | joined     | timestamp                             | NO   |     | CURRENT_TIMESTAMP |                |&lt;br /&gt;
 +------------+---------------------------------------+------+-----+-------------------+----------------+&lt;br /&gt;
 6 rows in set (0.00 sec)&lt;br /&gt;
 &lt;br /&gt;
 mysql&amp;gt; describe projects;&lt;br /&gt;
 +--------------+-----------------------+------+-----+---------+----------------+&lt;br /&gt;
 | Field        | Type                  | Null | Key | Default | Extra          |&lt;br /&gt;
 +--------------+-----------------------+------+-----+---------+----------------+&lt;br /&gt;
 | id           | mediumint(8) unsigned | NO   | PRI | NULL    | auto_increment |&lt;br /&gt;
 | employee_id  | mediumint(8) unsigned | NO   | MUL | NULL    |                |&lt;br /&gt;
 | project_name | tinytext              | NO   |     | NULL    |                |&lt;br /&gt;
 +--------------+-----------------------+------+-----+---------+----------------+&lt;br /&gt;
 3 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
Further, suppose the tables had the following data:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select * from employees;&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 | id | first_name | last_name | nickname | department | joined              |&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 |  1 | John       | Doe       | NULL     | BME        | 2012-08-22 22:02:24 |&lt;br /&gt;
 |  2 | Keith      | Jones     | KK       | ESE        | 2012-08-22 22:02:24 |&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 2 rows in set (0.00 sec)&lt;br /&gt;
 &lt;br /&gt;
 mysql&amp;gt; select * from projects;&lt;br /&gt;
 +----+-------------+-----------------------------------+&lt;br /&gt;
 | id | employee_id | project_name                      |&lt;br /&gt;
 +----+-------------+-----------------------------------+&lt;br /&gt;
 |  1 |           1 | Interview the Chancellor          |&lt;br /&gt;
 |  2 |           1 | Give Presentation in Mumbai       |&lt;br /&gt;
 |  3 |           2 | Publish Research Paper in Journal |&lt;br /&gt;
 +----+-------------+-----------------------------------+&lt;br /&gt;
 3 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
If you ran the following query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	project_name,&lt;br /&gt;
	employees.first_name,&lt;br /&gt;
	employees.last_name&lt;br /&gt;
from projects&lt;br /&gt;
	join employees on (projects.employee_id=employees.id);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You would get the result:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select project_name, employees.first_name, employees.last_name from projects&lt;br /&gt;
     -&amp;gt; join employees on (projects.employee_id=employees.id);&lt;br /&gt;
 +-----------------------------------+------------+-----------+&lt;br /&gt;
 | project_name                      | first_name | last_name |&lt;br /&gt;
 +-----------------------------------+------------+-----------+&lt;br /&gt;
 | Interview the Chancellor          | John       | Doe       |&lt;br /&gt;
 | Give Presentation in Mumbai       | John       | Doe       |&lt;br /&gt;
 | Publish Research Paper in Journal | Keith      | Jones     |&lt;br /&gt;
 +-----------------------------------+------------+-----------+&lt;br /&gt;
 3 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
Isn't that cool?&lt;br /&gt;
&lt;br /&gt;
==== Inner Joins, Left Joins, Right Joins, and Full Joins ====&lt;br /&gt;
&lt;br /&gt;
When you perform a '''JOIN''' like we did above, you are implicitly performing an '''INNER JOIN'''.  However, there may be times when you want to select data in a query even if it doesn't have a complement in the joined table.  For example, suppose Keith Jones cancelled his project.  The projects table now contains the following data:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select * from projects;&lt;br /&gt;
 +----+-------------+-----------------------------+&lt;br /&gt;
 | id | employee_id | project_name                |&lt;br /&gt;
 +----+-------------+-----------------------------+&lt;br /&gt;
 |  1 |           1 | Interview the Chancellor    |&lt;br /&gt;
 |  2 |           1 | Give Presentation in Mumbai |&lt;br /&gt;
 +----+-------------+-----------------------------+&lt;br /&gt;
 2 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
Now, we could run the following query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	count(projects.id) as project_num,&lt;br /&gt;
	employees.first_name,&lt;br /&gt;
	employees.last_name&lt;br /&gt;
from employees&lt;br /&gt;
	join projects on (employees.id=projects.employee_id)&lt;br /&gt;
group by employees.id;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We get the result:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select count(projects.id) as project_num, employees.first_name, employees.last_name from employees&lt;br /&gt;
     -&amp;gt; join projects on (employees.id=projects.employee_id) group by employees.id;&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 | project_num | first_name | last_name |&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 |           2 | John       | Doe       |&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 1 row in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
But where's Keith Jones?  Since Keith Jones didn't have any projects, he was omitted from the result.  This is probably not what we intended to happen.  Instead, you should perform a '''LEFT JOIN''', like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	count(projects.id) as project_num,&lt;br /&gt;
	employees.first_name,&lt;br /&gt;
	employees.last_name&lt;br /&gt;
from employees&lt;br /&gt;
	left join projects on (employees.id=projects.employee_id)&lt;br /&gt;
group by employees.id;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result will now be:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select count(projects.id) as project_num, employees.first_name, employees.last_name from employees&lt;br /&gt;
     -&amp;gt; left join projects on (employees.id=projects.employee_id) group by employees.id;&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 | project_num | first_name | last_name |&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 |           2 | John       | Doe       |&lt;br /&gt;
 |           0 | Keith      | Jones     |&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 2 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
(For more information on COUNT and GROUP BY, see [[#Aggregation Clauses|a later section]].)&lt;br /&gt;
&lt;br /&gt;
You can see that a LEFT JOIN preserves all rows from the &amp;quot;left&amp;quot; table in the join.  Likewise, a RIGHT JOIN preserves all rows from the &amp;quot;right&amp;quot; table.  A FULL JOIN preserves all rows from both tables.&lt;br /&gt;
&lt;br /&gt;
=== WHERE Clauses ===&lt;br /&gt;
&lt;br /&gt;
If you want to select data that satisfies a condition, use a '''WHERE''' clause.&lt;br /&gt;
&lt;br /&gt;
A simple '''WHERE''' clause can use equality, less than, greater than, and most other comparison operators.  For example, the following query selects all last names of employees with an Employee ID of less than 10:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	last_name&lt;br /&gt;
from employees&lt;br /&gt;
where&lt;br /&gt;
	employee_id &amp;lt; 10;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we wanted to select everyone from our employees table whose name started with a J, we could use a '''LIKE''' statement in our '''WHERE''' clause:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	first_name,&lt;br /&gt;
	last_name&lt;br /&gt;
from employees&lt;br /&gt;
where&lt;br /&gt;
	first_name like 'J%';&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The '''LIKE''' clause is SQL's way of letting you perform simple tests on strings.  (SQL's built-in string comparison operations are not as powerful as regular expressions, but they'll get the job done in most everyday situations.)&lt;br /&gt;
&lt;br /&gt;
=== Sorting Data ===&lt;br /&gt;
&lt;br /&gt;
You can sort data using an '''ORDER BY''' clause like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	first_name,&lt;br /&gt;
	last_name&lt;br /&gt;
from employees&lt;br /&gt;
order by last_name asc;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you wanted to select only the first few results from a query, use the '''LIMIT''' clause:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	first_name,&lt;br /&gt;
	last_name&lt;br /&gt;
from employees&lt;br /&gt;
order by last_name asc&lt;br /&gt;
limit 10;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is important to note that the ORDER BY on a field is performed ''after'' aggregation functions.  Currently, there is no way in MySQL to perform sorting ''before'' aggregation has occurred in a single query; we need to resort to nested queries.  (For example, in the baseball example below, it's not easy to select &amp;quot;the player from each team with the highest batting average&amp;quot;.  It's even harder, if not impossible, to select &amp;quot;the ''three'' players from each team with the highest batting averages&amp;quot;.)&lt;br /&gt;
&lt;br /&gt;
=== Aggregation Clauses ===&lt;br /&gt;
&lt;br /&gt;
When performing computations on an entire database, you will probably find yourself wanting to use ''aggregation functions''.  Aggregation functions include:&lt;br /&gt;
&lt;br /&gt;
* '''AVG(column_name)''' to compute the average value of column_name&lt;br /&gt;
* '''STD(column_name)''' to compute the standard deviation of column_name&lt;br /&gt;
* '''SUM(column_name)''' to compute the sum&lt;br /&gt;
* '''MIN(column_name)''' to find the minimum value&lt;br /&gt;
* '''MAX(column_name)''' to fund the maximum value&lt;br /&gt;
* '''COUNT(column_name)''' to count the total number of entries having a not null entry in column_name&lt;br /&gt;
&lt;br /&gt;
For example, if you had a table containing batter averages, you could calculate the mean batter average using this query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since WHERE clauses are performed ''before'' aggregation, you can also perform a query like&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players&lt;br /&gt;
where&lt;br /&gt;
	team_id=5;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to aggregate all rows that share a certain value in an index, use a '''GROUP BY''' clause.  For example, to select the average batter average for all teams, you could do&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players&lt;br /&gt;
group by team_id;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may find yourself wanting to apply a condition after the aggregation has occurred.  You can do this using a '''HAVING''' clause.  For example, the following query would select all baseball teams whose average batter average is more than 300:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players&lt;br /&gt;
group by team_id&lt;br /&gt;
having&lt;br /&gt;
	avg_batter_average &amp;gt; 300;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is perfectly valid to combine WHERE and HAVING clauses in a single query.  For example, the following query first finds all players whose first name starts with &amp;quot;J&amp;quot;, averages their batting averages together by team, and then selects those teams whose average batting average of the &amp;quot;J&amp;quot; players is more than 300; that is, it selects those teams &amp;quot;whose average batting average of players whose first name starts with J is more than 300&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players&lt;br /&gt;
where&lt;br /&gt;
	first_name like &amp;quot;J%&amp;quot;&lt;br /&gt;
group by team_id&lt;br /&gt;
having&lt;br /&gt;
	avg_batter_average &amp;gt; 300;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
	<entry>
		<id>http://classes.engineering.wustl.edu/cse330/index.php?title=MySQL_Schema_and_State&amp;diff=2848</id>
		<title>MySQL Schema and State</title>
		<link rel="alternate" type="text/html" href="http://classes.engineering.wustl.edu/cse330/index.php?title=MySQL_Schema_and_State&amp;diff=2848"/>
		<updated>2023-01-10T06:00:02Z</updated>

		<summary type="html">&lt;p&gt;Zach: /* Foreign Key */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;MySQL is a powerful database that allows for complex logic when manipulating data.  This guide is an introduction and a reference to common SQL queries for schema and state manipulation.&lt;br /&gt;
&lt;br /&gt;
This guide assumes that you already have a working copy of MySQL.  If you don't, read [[Introduction to MySQL]] first.&lt;br /&gt;
&lt;br /&gt;
==Schema ==&lt;br /&gt;
&lt;br /&gt;
The ''schema'' of your database refers to the way that your data is structured and to how bits of data relate to each other.  Every database in your MySQL server has a separate schema, and separate databases should not typically interact with one another.&lt;br /&gt;
&lt;br /&gt;
=== Tables ===&lt;br /&gt;
&lt;br /&gt;
A database contains one or more ''tables''.  Tables contain columns and rows, which you may sometimes call ''fields'' and ''entries''.&lt;br /&gt;
&lt;br /&gt;
You can see all of the tables in the database using this query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
show tables;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When you create a table, you should provide information about all of that table's columns within the ''create table'' query.  Here is the general syntax for the query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
create table &amp;lt;TABLENAME&amp;gt; (&lt;br /&gt;
	&amp;lt;FIELDNAME&amp;gt; &amp;lt;DATATYPE&amp;gt; &amp;lt;OPTIONS&amp;gt;,&lt;br /&gt;
	&amp;lt;FIELDNAME&amp;gt; &amp;lt;DATATYPE&amp;gt; &amp;lt;OPTIONS&amp;gt;,&lt;br /&gt;
	&amp;lt;FIELDNAME&amp;gt; &amp;lt;DATATYPE&amp;gt; &amp;lt;OPTIONS&amp;gt;,&lt;br /&gt;
	&amp;lt;FIELDNAME&amp;gt; &amp;lt;DATATYPE&amp;gt; &amp;lt;OPTIONS&amp;gt;&lt;br /&gt;
) &amp;lt;TABLE_OPTIONS&amp;gt;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can get details about an existing table using this query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
describe &amp;lt;TABLENAME&amp;gt;;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Data Types ====&lt;br /&gt;
&lt;br /&gt;
Just like a programming language, MySQL has data types.  There are dozens of data types; some of the most common ones are documented below.&lt;br /&gt;
&lt;br /&gt;
===== String Data Types =====&lt;br /&gt;
&lt;br /&gt;
There are four main types of string data types: character, text, blob, and enumerable.&lt;br /&gt;
&lt;br /&gt;
* Character types are useful for short strings, like usernames and e-mail addresses.&lt;br /&gt;
* Text types differ from character types in that behind the scenes, they are not actually stored with the rest of the table row; they are useful for longer blocks of text, like forum posts.&lt;br /&gt;
* Blobs are for binary data, like files.&lt;br /&gt;
* Enumerables are for something that could have one of a set number of values (not more than 65535), like what State a user is from (Alabama, Alaska, and so on).  Enums are also useful for storing boolean data, like '''ENUM('yes','no')'''.  An enum is actually stored as an integer in the database, making queries more efficient.&lt;br /&gt;
&lt;br /&gt;
The syntax for these data types is:&lt;br /&gt;
&lt;br /&gt;
* '''VARCHAR(#)''', a string ''at most'' # characters long, where 0 ≤ # ≤ 65535&lt;br /&gt;
* '''CHAR(#)''', a string ''exactly'' # characters long, where 0 ≤ # ≤ 65535&lt;br /&gt;
* '''TINYTEXT''', a text block at most 255 characters long&lt;br /&gt;
* '''TEXT''', a text block at most 65535 characters long&lt;br /&gt;
* '''LONGTEXT''', a text block at most 4 GB in length&lt;br /&gt;
* '''BLOB''', a binary string at most 65 KB in length&lt;br /&gt;
* '''MEDIUMBLOB''', a binary string at most 16 MB in length&lt;br /&gt;
* '''LONGBLOB''', a binary string at most 4 GB in length&lt;br /&gt;
* '''ENUM('a', 'b', 'c')''', an enumerable with choices a, b, and c&lt;br /&gt;
&lt;br /&gt;
===== Numeric Data Types =====&lt;br /&gt;
&lt;br /&gt;
There are two types of numeric data types that you need to worry about: integers and decimals.  The difference between the two should be pretty self-explanatory.  The syntax for using these data types is:&lt;br /&gt;
&lt;br /&gt;
* '''TINYINT''', an integer ''n'' where -128 ≤ n ≤ 127&lt;br /&gt;
* '''TINYINT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 255&lt;br /&gt;
* '''SMALLINT''', an integer ''n'' where -32,768 ≤ n ≤ 32,767&lt;br /&gt;
* '''SMALLINT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 65,535&lt;br /&gt;
* '''MEDIUMINT''', an integer ''n'' where -8,388,608 ≤ n ≤ 8,388,607&lt;br /&gt;
* '''MEDIUMINT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 16,777,215&lt;br /&gt;
* '''INT''', an integer ''n'' where -2,147,483,648 ≤ n ≤ 2,147,483,647&lt;br /&gt;
* '''INT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 4,294,967,295&lt;br /&gt;
* '''BIGINT''', an integer ''n'' where -9,223,372,036,854,775,808 ≤ n ≤ 9,223,372,036,854,775,807&lt;br /&gt;
* '''BIGINT UNSIGNED''', an integer ''n'' where 0 ≤ n ≤ 18,446,744,073,709,551,615&lt;br /&gt;
* '''DECIMAL(#a, #b)''', a decimal number at most ''#a'' digits long, ''#b'' of which are after the decimal point.  For example, ''DECIMAL(5,2)'' can contain ''n'' where -999.99 ≤ n ≤ 999.99&lt;br /&gt;
&lt;br /&gt;
When choosing the size of an integer, you should use the ''smallest integer for which you know you will never &amp;quot;run out of room&amp;quot;''.  In most everyday circumstances, '''MEDIUMINT''' should be the biggest you'll need.&lt;br /&gt;
&lt;br /&gt;
===== Temporal Data Types =====&lt;br /&gt;
{{XKCD&lt;br /&gt;
|name=2038&lt;br /&gt;
|id=607&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
MySQL provides a class of data types that specialize in handling dates and times.  The syntax for using date types is:&lt;br /&gt;
&lt;br /&gt;
* '''DATE''', a date ''d'' where &amp;lt;code&amp;gt;1000-01-01&amp;lt;/code&amp;gt; ≤ d ≤ &amp;lt;code&amp;gt;9999-12-31&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''DATETIME''', a date with time ''d'' where &amp;lt;code&amp;gt;1000-01-01 00:00:00&amp;lt;/code&amp;gt; ≤ d ≤ &amp;lt;code&amp;gt;9999-12-31 23:59:59&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''TIMESTAMP''', a date with time ''d'' where &amp;lt;code&amp;gt;1970-01-01 00:00:01 UTC&amp;lt;/code&amp;gt; ≤ d ≤ &amp;lt;code&amp;gt;2038-01-19 03:14:07 UTC&amp;lt;/code&amp;gt; (note: &amp;lt;code&amp;gt;1970-01-01 00:00:01 UTC&amp;lt;/code&amp;gt; is the Unix epoch)&lt;br /&gt;
* '''TIME''', a length of time ''t'' where &amp;lt;code&amp;gt;-838:59:59&amp;lt;/code&amp;gt; ≤ t ≤ &amp;lt;code&amp;gt;838:59:59&amp;lt;/code&amp;gt; (note: you cannot store time to a precision greater than 1 second)&lt;br /&gt;
* '''YEAR''', a year ''y'' where 1901 ≤ y ≤ 2155&lt;br /&gt;
&lt;br /&gt;
Note that '''TIMESTAMP''' is a highly versatile data type that can automatically change whenever a row is updated.  For more information, refer to [http://dev.mysql.com/doc/refman/5.6/en/timestamp-initialization.html the MySQL documentation].&lt;br /&gt;
&lt;br /&gt;
==== Field Options ====&lt;br /&gt;
&lt;br /&gt;
By default, any &amp;quot;cell&amp;quot; in a MySQL table can contain the ''NULL'' value.  If a certain field in your database schema will never contain a null value, you should declare it as '''NOT NULL''' in order to make queries more efficient.&lt;br /&gt;
&lt;br /&gt;
You can also specify a default value for a field.  If you do, when you insert data into the table, it won't be necessary to specify a value for that column.  To specify a default value for a field, use the syntax '''DEFAULT 'DEFAULT-VALUE' '''&lt;br /&gt;
&lt;br /&gt;
==== Create Table Example ====&lt;br /&gt;
&lt;br /&gt;
The following query would create a table called ''employees'' with six columns: employee ID, first name, last name, nickname, department, and the date that they joined the company.  Nickname is the only optional column.  The primary key for the table (see the next section) will be the ''id'' column.  The department will be one of five choices, with the default being CSE.  The storage engine for the table will be InnoDB, and the default charset for the table will be UTF8.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
create table employees (&lt;br /&gt;
	id mediumint unsigned not null auto_increment,&lt;br /&gt;
	first_name varchar(30) not null,&lt;br /&gt;
	last_name varchar(40) not null,&lt;br /&gt;
	nickname varchar(20),&lt;br /&gt;
	department enum('CSE','BME','EECE','ESE','MEMS') not null default 'CSE',&lt;br /&gt;
	joined timestamp not null default current_timestamp,&lt;br /&gt;
	primary key (id)&lt;br /&gt;
) engine = InnoDB default character set = utf8 collate = utf8_general_ci;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Keys ===&lt;br /&gt;
&lt;br /&gt;
When MySQL goes to get data out of a database, it does so using an index, like the index of a textbook.  In tech talk, we call indices ''keys''.&lt;br /&gt;
&lt;br /&gt;
==== Primary Key ====&lt;br /&gt;
&lt;br /&gt;
The '''primary key''' is what MySQL uses to distinguish one row from another.  Every table must have exactly one primary key; no more, no less.&lt;br /&gt;
&lt;br /&gt;
It is common practice to add a column to a table with data type '''mediumint unsigned not null auto_increment''' to serve as the primary key for a table.  The '''auto_increment''' is a neat little feature of MySQL that basically says, &amp;quot;when a new row is inserted into this table, assign it the next-lowest available ID&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
To specify a primary key for a table, use the syntax:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
primary key (column1, column2, column3)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unique Key ====&lt;br /&gt;
&lt;br /&gt;
If you want to specify that all items in a certain column will be unique from each other (like usernames or e-mail addresses), you can use a '''unique key'''.&lt;br /&gt;
&lt;br /&gt;
Because a table can have more than one unique key, you need to give your unique key a name.  It is common practice to name the key after the columns it is indexing, like ''idx_unique_column1_column2''.&lt;br /&gt;
&lt;br /&gt;
The syntax for specifying a unique key is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
unique key &amp;lt;INDEX_NAME&amp;gt; (&amp;lt;column1&amp;gt;, &amp;lt;column2&amp;gt;, &amp;lt;column3&amp;gt;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Foreign Key ====&lt;br /&gt;
&lt;br /&gt;
A '''foreign key''' is the most complicated type of MySQL index.  A foreign key says that the values in one column or columns are associated with the values in a column or columns in a ''different table''.&lt;br /&gt;
&lt;br /&gt;
For example, suppose you had two tables, one containing users and the other containing posts on a forum.  There is a one-to-many relationship between users and posts.  You could link a post to a user by having a column in your post table called ''user_id'', which would be a ''foreign key'' to the ''id'' column in your users table.&lt;br /&gt;
&lt;br /&gt;
Foreign keys can be a source of great confusion in developing database schemas.  If you get stuck, keep this tip in mind: '''Foreign Keys should always reference the columns used in the Primary Key of a different table.'''&lt;br /&gt;
&lt;br /&gt;
The syntax for creating a foreign key is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
foreign key (&amp;lt;column1&amp;gt;, &amp;lt;column2&amp;gt;, &amp;lt;column3&amp;gt;) references &amp;lt;FOREIGN_TABLENAME&amp;gt; (&amp;lt;column1&amp;gt;, &amp;lt;column2&amp;gt;, &amp;lt;column3&amp;gt;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, in the user-and-post example above, the foreign key declaration would be:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
foreign key (user_id) references user (id)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===== Further Reading about Foreign Keys =====&lt;br /&gt;
&lt;br /&gt;
* [[wikipedia:Foreign Key|Wikipedia Entry on Foreign Keys]]&lt;br /&gt;
* [http://www.techrepublic.com/article/an-introduction-to-foreign-keys-and-referential-integrity-in-mysql/6035435 An introductory article on Tech Republic]&lt;br /&gt;
* [http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html MySQL Documentation for Foreign Keys]&lt;br /&gt;
&lt;br /&gt;
==== Syntax for Keys ====&lt;br /&gt;
&lt;br /&gt;
You can define keys in your '''create table''' query, or you can define them later.&lt;br /&gt;
&lt;br /&gt;
If you define them in your '''create table''' query, do so after the column definitions but still inside the parentheses:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
create table TABLENAME (&lt;br /&gt;
	column,&lt;br /&gt;
	column,&lt;br /&gt;
	....,&lt;br /&gt;
	primary key (column1, column2, ...),&lt;br /&gt;
	unique key INDEXNAME (column1, column2, ...),&lt;br /&gt;
	foreign key (column1, column2, ...) references FOREIGN_TABLENAME (column1, column2, ...)&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To define indices later, use an '''ALTER TABLE''' query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
alter table TABLENAME add unique key INDEXNAME (column1, column2, ...);&lt;br /&gt;
alter table TABLENAME add foreign key (column1, column2, ...) references FOREIGN_TABLENAME (column1, column2, ...);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== State ==&lt;br /&gt;
&lt;br /&gt;
The ''state'' of your database refers to the data that it holds.  Whenever you insert, update, or delete data, the state of your database changes.&lt;br /&gt;
&lt;br /&gt;
=== Inserting Data from a Query ===&lt;br /&gt;
&lt;br /&gt;
To insert a row (aka ''entry'') into a table, use a query of the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
insert into TABLENAME (column1, column2, column3) values (value1_1, value2_1, value3_1), (value1_2, value2_2, value3_2), ...&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, to insert an employee into the table we created earlier, you could use the query&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
insert into employees (first_name, last_name, department) values ('John', 'Doe', 'BME'), ('Keith', 'Jones', 'ESE');&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because of the various default and auto_increment values we have specified in our database, the database would now contain the following data:&lt;br /&gt;
&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 | id | first_name | last_name | nickname | department | joined              |&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 |  1 | John       | Doe       | NULL     | BME        | 2012-08-22 22:02:24 |&lt;br /&gt;
 |  2 | Keith      | Jones     | NULL     | ESE        | 2012-08-22 22:02:24 |&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
&lt;br /&gt;
If you want to insert a DATE or DATETIME value into a database, use the YYYY-MM-DD HH:MM:SS format.  The exception is with TIMESTAMP, in which you should use a 16-bit integer representing the number of seconds since January 1, 1970.&lt;br /&gt;
&lt;br /&gt;
=== Inserting Data from a File ===&lt;br /&gt;
&lt;br /&gt;
The '''load data infile''' command populates a table using data stored in a text file. The general form of the command is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
LOAD DATA INFILE 'dataFile.txt' INTO TABLE table_name;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where ''dataFile.txt'' is located relative to the server's data directory if a path name with leading components is given; otherwise, if no leading components are given, the server assumes the file is in the default database's database directory.  If an absolute path is specified, the server uses it. For this command to work, you must issue the following command to grant the FILE privilege to your user:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
GRANT FILE on *.* to 'user'@'host';&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Alternatively, and quite usefully, you can load data from a local file (a file residing on the same machine as the client) using the LOCAL keyword. When loading data from the local machine you do not need to grant your user the FILE privilege, think about why this might be the case.  (Hint: what is going on behind the scenes when you load the data in from a local machine when your database is hosted on a different machine?)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
LOAD DATA LOCAL INFILE '/home/linus_torvalds/Documents/dataFile.txt' INTO TABLE table_name;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note:''' When the local keyword is used, it is best to specify an absolute path.&lt;br /&gt;
&lt;br /&gt;
'''Additional Note:'''  If we SSH into our EC2 instance and then run the mysql command, the client is the EC2 instance, not the local computer that we SSH from. The LOCAL keyword in this case is allowing us to load files from the EC2 instance, not the local computer that we are using.&lt;br /&gt;
&lt;br /&gt;
By default, the text files are assumed to have tab-delimited columns with column values specified in the same order as they are defined in the table (though you can specify additional/alternative delimiters using additional options).&lt;br /&gt;
&lt;br /&gt;
=== Updating Data ===&lt;br /&gt;
&lt;br /&gt;
To update a row in a table, use a query of the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
update TABLENAME set column1=value1, column2=value2, column3=value3 where CONDITION&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, to set Keith Jones's nickname to &amp;quot;KJ&amp;quot;, you would run the query&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
update employees set nickname='KJ' where id=2;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Deleting Data ===&lt;br /&gt;
&lt;br /&gt;
To delete a row from a table, use a query of the form&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
delete from TABLENAME where CONDITION&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For example, to delete John Doe from the table, you would run the query&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
delete from employees where id=1;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''DO NOT FORGET THE WHERE CLAUSE!'''  If you do, ''all'' rows will be deleted from your table!&lt;br /&gt;
&lt;br /&gt;
== Selecting Data ==&lt;br /&gt;
&lt;br /&gt;
The most simple query to select data from a table is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select * from TABLENAME;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, in practice, you will almost always want to perform a more advanced query.&lt;br /&gt;
&lt;br /&gt;
=== Selecting Specific Columns ===&lt;br /&gt;
&lt;br /&gt;
In order to save transmission time, you should select only those columns that you need in your application.  The syntax for selecting only certain columns is&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select column1, column2, column3 from TABLENAME;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computation ===&lt;br /&gt;
&lt;br /&gt;
MySQL can perform computation.  For example, if you wanted to select the amount of time that a certain employee has been at the company, you could run the query&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select TIMESTAMPDIFF( second, joined, NOW() ) as time_with_company from employees;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Joins ===&lt;br /&gt;
&lt;br /&gt;
When you have one-to-one, one-to-many, or many-to-many relationships between tables, you will often want to select data from multiple tables in one query.  To do this, use '''joins'''.&lt;br /&gt;
&lt;br /&gt;
Joins are best described by example.  Suppose you had the following tables in a MySQL database:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; describe employees;&lt;br /&gt;
 +------------+---------------------------------------+------+-----+-------------------+----------------+&lt;br /&gt;
 | Field      | Type                                  | Null | Key | Default           | Extra          |&lt;br /&gt;
 +------------+---------------------------------------+------+-----+-------------------+----------------+&lt;br /&gt;
 | id         | mediumint(8) unsigned                 | NO   | PRI | NULL              | auto_increment |&lt;br /&gt;
 | first_name | varchar(30)                           | NO   |     | NULL              |                |&lt;br /&gt;
 | last_name  | varchar(40)                           | NO   |     | NULL              |                |&lt;br /&gt;
 | nickname   | varchar(20)                           | YES  |     | NULL              |                |&lt;br /&gt;
 | department | enum('CSE','BME','EECE','ESE','MEMS') | NO   |     | CSE               |                |&lt;br /&gt;
 | joined     | timestamp                             | NO   |     | CURRENT_TIMESTAMP |                |&lt;br /&gt;
 +------------+---------------------------------------+------+-----+-------------------+----------------+&lt;br /&gt;
 6 rows in set (0.00 sec)&lt;br /&gt;
 &lt;br /&gt;
 mysql&amp;gt; describe projects;&lt;br /&gt;
 +--------------+-----------------------+------+-----+---------+----------------+&lt;br /&gt;
 | Field        | Type                  | Null | Key | Default | Extra          |&lt;br /&gt;
 +--------------+-----------------------+------+-----+---------+----------------+&lt;br /&gt;
 | id           | mediumint(8) unsigned | NO   | PRI | NULL    | auto_increment |&lt;br /&gt;
 | employee_id  | mediumint(8) unsigned | NO   | MUL | NULL    |                |&lt;br /&gt;
 | project_name | tinytext              | NO   |     | NULL    |                |&lt;br /&gt;
 +--------------+-----------------------+------+-----+---------+----------------+&lt;br /&gt;
 3 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
Further, suppose the tables had the following data:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select * from employees;&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 | id | first_name | last_name | nickname | department | joined              |&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 |  1 | John       | Doe       | NULL     | BME        | 2012-08-22 22:02:24 |&lt;br /&gt;
 |  2 | Keith      | Jones     | KK       | ESE        | 2012-08-22 22:02:24 |&lt;br /&gt;
 +----+------------+-----------+----------+------------+---------------------+&lt;br /&gt;
 2 rows in set (0.00 sec)&lt;br /&gt;
 &lt;br /&gt;
 mysql&amp;gt; select * from projects;&lt;br /&gt;
 +----+-------------+-----------------------------------+&lt;br /&gt;
 | id | employee_id | project_name                      |&lt;br /&gt;
 +----+-------------+-----------------------------------+&lt;br /&gt;
 |  1 |           1 | Interview the Chancellor          |&lt;br /&gt;
 |  2 |           1 | Give Presentation in Mumbai       |&lt;br /&gt;
 |  3 |           2 | Publish Research Paper in Journal |&lt;br /&gt;
 +----+-------------+-----------------------------------+&lt;br /&gt;
 3 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
If you ran the following query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	project_name,&lt;br /&gt;
	employees.first_name,&lt;br /&gt;
	employees.last_name&lt;br /&gt;
from projects&lt;br /&gt;
	join employees on (projects.employee_id=employees.id);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You would get the result:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select project_name, employees.first_name, employees.last_name from projects&lt;br /&gt;
     -&amp;gt; join employees on (projects.employee_id=employees.id);&lt;br /&gt;
 +-----------------------------------+------------+-----------+&lt;br /&gt;
 | project_name                      | first_name | last_name |&lt;br /&gt;
 +-----------------------------------+------------+-----------+&lt;br /&gt;
 | Interview the Chancellor          | John       | Doe       |&lt;br /&gt;
 | Give Presentation in Mumbai       | John       | Doe       |&lt;br /&gt;
 | Publish Research Paper in Journal | Keith      | Jones     |&lt;br /&gt;
 +-----------------------------------+------------+-----------+&lt;br /&gt;
 3 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
Isn't that cool?&lt;br /&gt;
&lt;br /&gt;
==== Inner Joins, Left Joins, Right Joins, and Full Joins ====&lt;br /&gt;
&lt;br /&gt;
When you perform a '''JOIN''' like we did above, you are implicitly performing an '''INNER JOIN'''.  However, there may be times when you want to select data in a query even if it doesn't have a complement in the joined table.  For example, suppose Keith Jones cancelled his project.  The projects table now contains the following data:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select * from projects;&lt;br /&gt;
 +----+-------------+-----------------------------+&lt;br /&gt;
 | id | employee_id | project_name                |&lt;br /&gt;
 +----+-------------+-----------------------------+&lt;br /&gt;
 |  1 |           1 | Interview the Chancellor    |&lt;br /&gt;
 |  2 |           1 | Give Presentation in Mumbai |&lt;br /&gt;
 +----+-------------+-----------------------------+&lt;br /&gt;
 2 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
Now, we could run the following query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	count(projects.id) as project_num,&lt;br /&gt;
	employees.first_name,&lt;br /&gt;
	employees.last_name&lt;br /&gt;
from employees&lt;br /&gt;
	join projects on (employees.id=projects.employee_id)&lt;br /&gt;
group by employees.id;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We get the result:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select count(projects.id) as project_num, employees.first_name, employees.last_name from employees&lt;br /&gt;
     -&amp;gt; join projects on (employees.id=projects.employee_id) group by employees.id;&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 | project_num | first_name | last_name |&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 |           2 | John       | Doe       |&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 1 row in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
But where's Keith Jones?  Since Keith Jones didn't have any projects, he was omitted from the result.  This is probably not what we intended to happen.  Instead, you should perform a '''LEFT JOIN''', like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	count(projects.id) as project_num,&lt;br /&gt;
	employees.first_name,&lt;br /&gt;
	employees.last_name&lt;br /&gt;
from employees&lt;br /&gt;
	left join projects on (employees.id=projects.employee_id)&lt;br /&gt;
group by employees.id;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result will now be:&lt;br /&gt;
&lt;br /&gt;
 mysql&amp;gt; select count(projects.id) as project_num, employees.first_name, employees.last_name from employees&lt;br /&gt;
     -&amp;gt; left join projects on (employees.id=projects.employee_id) group by employees.id;&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 | project_num | first_name | last_name |&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 |           2 | John       | Doe       |&lt;br /&gt;
 |           0 | Keith      | Jones     |&lt;br /&gt;
 +-------------+------------+-----------+&lt;br /&gt;
 2 rows in set (0.00 sec)&lt;br /&gt;
&lt;br /&gt;
(For more information on COUNT and GROUP BY, see [[#Aggregation Clauses|a later section]].)&lt;br /&gt;
&lt;br /&gt;
You can see that a LEFT JOIN preserves all rows from the &amp;quot;left&amp;quot; table in the join.  Likewise, a RIGHT JOIN preserves all rows from the &amp;quot;right&amp;quot; table.  A FULL JOIN preserves all rows from both tables.&lt;br /&gt;
&lt;br /&gt;
=== WHERE Clauses ===&lt;br /&gt;
&lt;br /&gt;
If you want to select data that satisfies a condition, use a '''WHERE''' clause.&lt;br /&gt;
&lt;br /&gt;
A simple '''WHERE''' clause can use equality, less than, greater than, and most other comparison operators.  For example, the following query selects all last names of employees with an Employee ID of less than 10:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	last_name&lt;br /&gt;
from employees&lt;br /&gt;
where&lt;br /&gt;
	employee_id &amp;lt; 10;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If we wanted to select everyone from our employees table whose name started with a J, we could use a '''LIKE''' statement in our '''WHERE''' clause:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	first_name,&lt;br /&gt;
	last_name&lt;br /&gt;
from employees&lt;br /&gt;
where&lt;br /&gt;
	first_name like 'J%';&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The '''LIKE''' clause is SQL's way of letting you perform simple tests on strings.  (SQL's built-in string comparison operations are not as powerful as regular expressions, but they'll get the job done in most everyday situations.)&lt;br /&gt;
&lt;br /&gt;
=== Sorting Data ===&lt;br /&gt;
&lt;br /&gt;
You can sort data using an '''ORDER BY''' clause like so:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	first_name,&lt;br /&gt;
	last_name&lt;br /&gt;
from employees&lt;br /&gt;
order by last_name asc;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you wanted to select only the first few results from a query, use the '''LIMIT''' clause:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	first_name,&lt;br /&gt;
	last_name&lt;br /&gt;
from employees&lt;br /&gt;
order by last_name asc&lt;br /&gt;
limit 10;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is important to note that the ORDER BY on a field is performed ''after'' aggregation functions.  Currently, there is no way in MySQL to perform sorting ''before'' aggregation has occurred in a single query; we need to resort to nested queries.  (For example, in the baseball example below, it's not easy to select &amp;quot;the player from each team with the highest batting average&amp;quot;.  It's even harder, if not impossible, to select &amp;quot;the ''three'' players from each team with the highest batting averages&amp;quot;.)&lt;br /&gt;
&lt;br /&gt;
=== Aggregation Clauses ===&lt;br /&gt;
&lt;br /&gt;
When performing computations on an entire database, you will probably find yourself wanting to use ''aggregation functions''.  Aggregation functions include:&lt;br /&gt;
&lt;br /&gt;
* '''AVG(column_name)''' to compute the average value of column_name&lt;br /&gt;
* '''STD(column_name)''' to compute the standard deviation of column_name&lt;br /&gt;
* '''SUM(column_name)''' to compute the sum&lt;br /&gt;
* '''MIN(column_name)''' to find the minimum value&lt;br /&gt;
* '''MAX(column_name)''' to fund the maximum value&lt;br /&gt;
* '''COUNT(column_name)''' to count the total number of entries having a not null entry in column_name&lt;br /&gt;
&lt;br /&gt;
For example, if you had a table containing batter averages, you could calculate the mean batter average using this query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Since WHERE clauses are performed ''before'' aggregation, you can also perform a query like&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players&lt;br /&gt;
where&lt;br /&gt;
	team_id=5;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want to aggregate all rows that share a certain value in an index, use a '''GROUP BY''' clause.  For example, to select the average batter average for all teams, you could do&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players&lt;br /&gt;
group by team_id;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may find yourself wanting to apply a condition after the aggregation has occurred.  You can do this using a '''HAVING''' clause.  For example, the following query would select all baseball teams whose average batter average is more than 300:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players&lt;br /&gt;
group by team_id&lt;br /&gt;
having&lt;br /&gt;
	avg_batter_average &amp;gt; 300;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It is perfectly valid to combine WHERE and HAVING clauses in a single query.  For example, the following query first finds all players whose first name starts with &amp;quot;J&amp;quot;, averages their batting averages together by team, and then selects those teams whose average batting average of the &amp;quot;J&amp;quot; players is more than 300; that is, it selects those teams &amp;quot;whose average batting average of players whose first name starts with J is more than 300&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;mysql&amp;quot;&amp;gt;&lt;br /&gt;
select&lt;br /&gt;
	avg(batter_average) as avg_batter_average&lt;br /&gt;
from baseball_players&lt;br /&gt;
where&lt;br /&gt;
	first_name like &amp;quot;J%&amp;quot;&lt;br /&gt;
group by team_id&lt;br /&gt;
having&lt;br /&gt;
	avg_batter_average &amp;gt; 300;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Module 3]]&lt;/div&gt;</summary>
		<author><name>Zach</name></author>
		
	</entry>
</feed>