University of Washington, CSE 190 M, Spring 2007
Lab 10: Final Exam Review ANSWERS

1. Ajax/XML

window.onload = load;

function load() {
	ajaxHelper("resources/q1.xml", createRect);
}

function createRect(ajax) {
	var character = ajax.responseXML.getElementsByTagName("shapes")[0];
	var rectangle = character.getElementsByTagName("rectangle")[0];
	var div = document.createElement("div");
	div.style.width = rectangle.getAttribute("width") + "px";
	div.style.height = rectangle.getAttribute("height") + "px";
	div.style.backgroundColor = "#" + rectangle.getAttribute("color");
	div.style.border = "2px solid black";
	document.body.appendChild(div);
}

2. PHP

<?php
$file = file_get_contents("employees.txt");
$employees = preg_split("/\n/", $file);

$found = FALSE;
foreach ($employees as $emp) {
	$info = preg_split("/\t/", $emp);
	if (strtolower($_GET['name']) == strtolower($info[0])) {
		$found = TRUE;
		$url = "http://awesomeco.com/";
		$url .= preg_replace("/ /", "", $info[2]);
		$url .= "/" . $info[1];
		print("<p>$info[0] is the <a href=\"$url\">$info[2]</a>.</p>");
	}
}

if (!$found) {
	print("<p>{$_GET['name']} is not an AwesomeCo employee.</p>");
}
?>

3. SQL

SELECT a1.fname, a2.fname, a2.lname, m.name
FROM   Actor a1, Actor a2, Cast c1, Cast c2, Movie m
WHERE  a1.lname = a2.lname
AND    c1.aid = a1.id
AND    c2.aid = a2.id
AND    c1.mid = c2.mid
AND    c1.mid = m.id
AND    a1.fname < a2.fname;