Yale University School of Art
1156 Chapel Street, POB 208339
New Haven, Connecticut, 06520-8339
(203) 432-2600
1156 Chapel Street, POB 208339
New Haven, Connecticut, 06520-8339
(203) 432-2600
ART
742B:
NETWORKS
&
TRANSACTIONS
1:
SPRING
2011
CONTENT MANAGEMENT SYSTEMS
- Aurora: Alter Altar
- Azusa: PARK-A-LINK
- Daniel: Live drops
- Heesun: â?§
- Jaewon: Diopter
- Jen: Dead Sounds
- Jessica: Finnegans Wake
- Julia: Places You Have Been
- Kristian: Patterns
- Njoki: Alteration/Iteration
- Nontsi: Music videos
- Ryan: Fragmentr
- Weiyi: The garden of forking paths
- Yenwei: Triangles
Last edited by: Julia Drummond Novitch
Edit access: Sysop
Edit access: Sysop
THE WEATHER
- Aurora:Now Screening
- Azusa:
- Daniel: Windows
- Heesun: relative weather
- Jaewon: Windy City
- Jen: Clear Night
- Jessica:
- Julia: Places You Will Go
- Kristian:
- Njoki: IMWDB
- Nontsi:Weather Patterns
- Ryan:
- Weiyi: h-t-m-l meteorological trifles
- Yenwei:
Last edited by: Julia Drummond Novitch
Edit access: Sysop
Edit access: Sysop
JUNCTIONS
- Aurora:
- Azusa: OVER/SHADOW
- Daniel:
- Heesun:obituaries
- Jaewon: Bus receipt
- Jen: Pawn Shops & Fine Dining
- Jessica:
- Julia:
- Kristian:
- Njoki: Book ’Em
- Nontsi:
- Ryan:
- Weiyi:
- Yenwei:
Last edited by: Julia Drummond Novitch
Edit access: Sysop
Edit access: Sysop
THE WEATHER
Right-click below to download sample RSS:
http://weather.yahooapis.com/forecastrss?p=06511
Feed Proxy for Firefox (makes it possible to click the above link normally, then view as usefully formatted XML)
Last edited by: Dan Michaelson
Edit access: Sysop
Edit access: Sysop
Lab 1: <?php ?>, Query parameters, and basic control structures
<?php
// ===== GET THE QUERY PARAMETERS =====
// Get $x from the "mars" parameter,
// for example ?mars=3
$x = $_REQUEST["mars"];
// Get $y from the "venus" parameter,
// for example ?mars=3&venus=2
$y = $x * $_REQUEST["venus"];
// ===== THIS CONTROL STRUCTURE IS CALLED A CONDITIONAL =====
// If y is bigger than 5, output "Big big big"
if ($y > 5) {
echo("Big");
echo(" Big big!");
// Nested condition-- only even evaluated if $y was > 5
if ($x > 4) {
echo(" It was mostly because of x. ");
}
}
// Otherwise, output "Small"
else {
echo("Small");
}
echo(" The product was $y");
// ===== THIS CONTROL STRUCTURE IS CALLED A LOOP
// Do a loop $y times
// It means:
// First set $i to 1
// Do the code block if $i <= $y
// Then increase $i by 1
// Then do the code block again if $i <= $y
// etc.
for ($i = 1; $i <= $y; $i++) {
// Each time through the outer loop,
// do this nested loop. This nested loop outputs $x quantity of !'s.
for ($j = 1; $j <= $x; $j++) {
echo("!");
}
// After we're done with the nested loop, output a space.
echo(" ");
}
?>
Hello <b>world</b>
Brrrrr
Last edited by: Dan Michaelson
Edit access: Designer, Sysop
Edit access: Designer, Sysop
Lab 2: Review of control structures (conditional and loop); HTML and HTML forms
<html>
<head>
<title>
This is the window title
</title>
</head>
<body>
<?php
// Only output anything if a number was specified in the request,
// which would not be the case if the user just came to the
// page for the first time to input stuff.
if (isset($_REQUEST["number"])) {
// ===== REQUEST PARAM =====
// Get the value of the "number" and "letter" parameters
$number = $_REQUEST["number"];
$letter = $_REQUEST["letter"];
// ===== CONDITIONAL =====
// Do one thing if it's exactly 50
// Always use ==, not =, for testing equality
// (single = is for assigning a value)
if ($number == 50) {
echo("That's my favorite number!");
echo(" Thank you for typing it.");
$unit = ":)";
echo(" $unit");
}
// Do another thing if it's NOT 50
else {
echo(" That number doesn't interest me much.");
$unit = ":(((";
echo(" $unit");
// If it's NOT 50, see if it's at least more than 25
if ($number > 25) {
echo(" But at least it's more than 25.");
$unit = ":-|";
echo(" $unit");
}
}
// This statement will be executed REGARDLESS of the above condition
echo(" Thank you for typing something.");
// ===== LOOP =====
// Outer loop from 1 through the number (for example 1 through 50)
for ($i = 1; $i <= $number; $i++) {
// Each time through the outer loop, print the emoticon we settled on
echo("$unit ");
// Each time through the outer loop, do an inner loop
// from 1 through half the number (for example 1 through 25).
// This inner loop should print a bunch of dots.
for ($j = 1; $j <= $number / 2; $j++) {
// Each time through the inner loop, print a dot
echo("$letter ");
}
}
}
?>
<form action="lab2.php">
<input type="text" name="number" />
<input type="text" name="letter" />
<input type="submit" />
</form>
<h1>
A good HTML resource is <a href="http://w3schools.com">w3schools.com</a>.
</h1>
In here you can put text.
You could make it <b>bold.</b>
<!-- <br /> is a self-closing tag -->
You<br />could add a line break.
A link to <a href="http://art.yale.edu/Art742b">our <i>class</i></a>.
<p>
This is a paragraph.
</p>
<p>
<a href="http://art.yale.edu">
<img src="http://www.stephengdewyer.com/Images_StephenGDewyer.com/2011yalesculpturemfathesisimage.jpg" width="200" height="200" />
</a>
</p>
</body>
</html>
Last edited by: Dan Michaelson
Edit access: Designer, Sysop
Edit access: Designer, Sysop
Lab 3: CSS, dynamic images
<html>
<head>
<title>PHP - Images</title>
<style>
body {
color: #666666;
font-family: Arial, Helvetica, Verdana, sans-serif;
font-size: 20px;
line-height: 25px;
background-color: yellow;
margin: 0;
padding: 0;
}
p {
margin: 0;
padding: 0;
text-indent: 15px;
}
.red {
color: red;
font-weight: bold;
font-size: 50px;
line-height: 80px;
text-transform: uppercase;
}
.image {
border: 5px solid red;
position: absolute;
top: 30px;
left: 200px;
}
#header {
background-color: green;
color: #fff; /* this is white */
font-size: 50px;
line-height: 50px;
padding: 30px;
margin: 0;
width: 500px;
position: fixed;
left: 100px;
top: 100px;
}
#content {
margin: 0 0 0 50px; /* margin-left: 50px; */
}
.character-info {
width: 400px;
}
</style>
</head>
<body>
<div id="header">
<p>This is <em>the title</em> of my page.</p>
</div>
<div id="content">
<div class="character-info">
<p>He is Ash's former rival. He is based on the character Blue from the videogames. Like his counterpart Blue, Gary hails from Pallet Town and is the grandson of renowned Pokémon researcher Professor Oak. At first, Gary was arrogant, always traveling with cheerleaders who only call out his name and constantly taunting Ash's group whenever they met. After losing in his first pokemon tournament, he despensed with the cheerleaders and has since become more open-minded. As Ash's rival, Gary usually thought of Ash as a poor trainer but he eventually came to accept Ash as his equal. Like Ash, Gary collected Gym badges and competed in Pokémon League tournaments; Kanto and Johto. After losing to Ash in the Johto League, he decides to pursue a career in Pokémon research, impeding his rivalry with Ash. After Ash defeats the Battle Frontier and comes back to Pallet Town, he and Ash have a battle with Gary's new Electivire and Ash's Pikachu. Electivire easily beats Pikachu, which inspires Ash to travel to Sinnoh. Appears in season 1-5 and 9-12. Gary's Japanese name, Shigeru Okido (ã?ªã?¼ã?ã?? ã?·ã?²ã?« Å?kido Shigeru?), is a reference to Shigeru Miyamoto, who mentored Pokémon creator Satoshi Tajiri.</p>
<p>He is Ash's former rival. He is based on the character Blue from the videogames. Like his counterpart Blue, Gary hails from Pallet Town and is the grandson of renowned Pokémon researcher Professor Oak. At first, Gary was arrogant, always traveling with cheerleaders who only call out his name and constantly taunting Ash's group whenever they met. After losing in his first pokemon tournament, he despensed with the cheerleaders and has since become more open-minded. As Ash's rival, Gary usually thought of Ash as a poor trainer but he eventually came to accept Ash as his equal. Like Ash, Gary collected Gym badges and competed in Pokémon League tournaments; Kanto and Johto. After losing to Ash in the Johto League, he decides to pursue a career in Pokémon research, impeding his rivalry with Ash. After Ash defeats the Battle Frontier and comes back to Pallet Town, he and Ash have a battle with Gary's new Electivire and Ash's Pikachu. Electivire easily beats Pikachu, which inspires Ash to travel to Sinnoh. Appears in season 1-5 and 9-12. Gary's Japanese name, Shigeru Okido (ã?ªã?¼ã?ã?? ã?·ã?²ã?« Å?kido Shigeru?), is a reference to Shigeru Miyamoto, who mentored Pokémon creator Satoshi Tajiri.</p>
</div>
<form action="lab3.php">
<select name="image">
<option value="1">Image 1</option>
<option value="2">Image 2</option>
<option value="3">Image 3</option>
<option value="4">Image 4</option>
<option value="5">Image 5</option>
<option value="6">Image 6</option>
<option value="100">Image 100</option>
</select>
<input type="submit" />
</form>
</div>
</body>
</html>
Last edited by: Dan Michaelson
Edit access: Designer, Sysop
Edit access: Designer, Sysop
Lab 4: Arrays, functions, and reading a file
<?php
/* ********** ARRAYS ********** */
// This is a normal variable
// $i = 2
$i = $_REQUEST["num"];
// This is an array. This is how you create a new array from scratch.
// This array has six elements.
$students = array("danny", "jen", "christian", "nontsi", "azusa", "jaewon");
// To get a particular element out of the array, specify an index-- in this case 2
// Arrays are 0-indexed, meaning that 0 gets you the first value, 1 the second, etc.
echo($students[$i]);
// Of course you can also change the values in an array
// This changes jen to alice
$students[1] = "alice";
// Some PHP functions operate on the entire array
// http://us2.php.net/manual/en/ref.array.php
// Implode turns a whole array into a string
$everyone = implode(" ----- ", $students);
echo("<br />");
echo($everyone);
// Explode turns a string into an array
$sentence = "The quick brown fox jumps over the lazy dog";
$words = explode(" ", $sentence);
echo("<br />");
echo($words[$i]);
/* ********** READING A FILE ********** */
// Read a file from the internet
$dictionary = file_get_contents("http://bert.art.yale.edu/~danmichaelson/words.txt");
// Split it up by line breaks
$dictionary_words = explode("\n", $dictionary);
// Echo some arbitrary word number that the user requested
echo("<br />");
echo($dictionary_words[$i]);
/* ********** FUNCTIONS ********** */
// Functions are a way of ENCAPSULATING code.
// This function outputs some text several times
// The first parameter is the text you want to output.
// The second parameter is how many times you want to output it.
// This function doesn't return anything, but it does output stuff directly.
function say_it_many_times($what, $how_many) {
for ($i = 0; $i < $how_many; $i += 1) {
echo($what);
echo(" ");
}
}
// This function converts farenheit to celsius.
// This function returns the celsius degrees.
// It doesn't output anything.
function celsius($farenheit) {
$c = ($farenheit - 32) * 5 / 9;
return $c;
}
echo("<br />");
say_it_many_times("CHECK", 4);
say_it_many_times("fff", 20);
echo("<br />");
echo(celsius($i));
?>
Last edited by: Dan Michaelson
Edit access: Designer, Sysop
Edit access: Designer, Sysop
Lab 4: Reading the weather!
<?php
$zip = $_REQUEST["zip"];
$raw_xml = file_get_contents("http://weather.yahooapis.com/forecastrss?p=$zip");
// Cheat a little
// This is because PHP's XML parser doesn't deal very easily
// with XML syntax such as "yweather:units". So just change all those to e.g. "units".
$raw_xml = str_replace("yweather:", "", $raw_xml);
$raw_xml = str_replace("geo:", "", $raw_xml);
// PARSE THE XML
// Get the root node
$xml = new SimpleXmlElement($raw_xml);
// Get the channel node within that
$channel = $xml->channel;
// Get the location node within that
$location = $channel->location;
// Get the city attribute of the location node
$city = $location['city'];
$region = $location['region'];
// Get the wind node and its attributes
$wind = $channel->wind;
$chill = $wind['chill'];
$direction = $wind['direction'];
$speed = $wind['speed'];
// Get the atmosphere node and its attributes
$atmosphere = $channel->atmosphere;
$humidity = $atmosphere['humidity'];
$visibility = $atmosphere['visibility'];
$pressure = $atmosphere['pressure'];
$rising = $atmosphere['rising'];
// Get the item node within the channel node
$item = $channel->item;
// Get the condition node within the item; and its attributes
$condition = $item->condition;
$condition_text = $condition['text'];
$condition_code = $condition['code'];
$temp = $condition['temp'];
// FUNCTION DEFINITIONS
function say_it_many_times($what, $how_many) {
for ($i = 0; $i < $how_many; $i += 1) {
echo($what);
echo(" ");
}
}
// DO SOMETHING WITH THE DATA WE HAVE NOW
echo($city);
echo("<br />");
say_it_many_times($condition_text, $speed);
?>
<img src="icon_<?= $condition_code ?>.png" />
<!-- Visibility: <?= $visibility ?> -->
<!-- Temperature: <?= $temp ?> -->
<!-- Condition code: <?= $condition_code ?> -->
Last edited by: Dan Michaelson
Edit access: Designer, Sysop
Edit access: Designer, Sysop
DATABASE INFO
Database browser app for Mac: Sequel Pro
- Host: ernie.art.yale.edu
- Username: networks
- Password: ********
Connect to database “nt1_2011”
Last edited by: Dan Michaelson
Edit access: Sysop
Edit access: Sysop
Lab 5-6: Database
<html>
<head>
<title>Trains</title>
</head>
<body>
<?php
// Connect to the database server
mysql_connect("ernie.art.yale.edu", "networks", "*******");
// Select our database
mysql_select_db("nt1_2011");
// Add a new row to the table if the form contents were passed
if (isset($_REQUEST["create_ride"])) {
$from = $_REQUEST['from'];
$to = $_REQUEST['to'];
$type = $_REQUEST['type'];
$departure_time = $_REQUEST['departure_time'];
$notes = $_REQUEST['notes'];
$result = mysql_query("INSERT INTO dan (`from`, `to`, `type`, `departure_time`, `notes`)
VALUES ('$from', '$to', '$type', '$departure_time', '$notes')");
}
// Display all rows in the table
$result = mysql_query("SELECT * FROM dan ORDER BY departure_time");
$num_rows = mysql_num_rows($result);
for ($i = 1; $i <= $num_rows; $i++) {
$row = mysql_fetch_assoc($result);
$from = $row['from'];
$to = $row['to'];
$type = $row['type'];
$departure_time = $row['departure_time'];
$notes = $row['notes'];
?>
<?= $departure_time ?>: <?= $from ?> → <?= $to ?> (<?= $type ?>)<br />
<?php if ($notes != '' && $notes != NULL) { ?>
---- <?= $notes ?><br />
<?php } ?>
<?php
}
?>
<hr />
<form action="trains.php">
From <input type="text" name="from" /><br />
To <input type="text" name="to" /><br />
Type <input type="text" name="type" /><br />
Departure time <input type="text" name="departure_time" /><br />
Notes <input type="text" name="notes" /><br />
<input type="submit" name="create_ride" value="Create train ride">
</form>
</body>
</html>
Last edited by: Dan Michaelson
Edit access: Designer, Sysop
Edit access: Designer, Sysop