CS 1520 Summer 2009 Quiz 2
SOLUTIONS
1) Short Answers (14 points – 8 + 6 points)
a) Consider the two MySQL Tables below. Assume that a movie's name is known and stored in the PHP variable $movie. Give and explain the MySQL query (or queries, using PHP syntax) that will produce the Titles of all Movies directed by the same director that directed $movie. For example, given the data below, if $movie = "Gladiator", the result of your query should be the Movie Titles "Alien", "Gladiator" and "Blade Runner". You do NOT have to print out the results.
Movies ID Title Year Direct_ID 1 The Godfather 1972 4 2 Goodfellas 1990 2 3 The Departed 2006 2 4 Top Gun 1986 3 5 Apocalypse Now 1979 4 6 Alien 1979 1 7 Gladiator 2000 1 8 Taxi Driver 1976 2 9 This Is Spinal
Tap 1984 5 10 Man on Fire 2004 3 11 The Princess
Bride 1987 5 12 Blade Runner 1982 1 ID Name 1 Ridley Scott 2 Martin Scorsese 3 Tony Scott 4 Francis Ford
Coppola 5 Rob Reiner
Directors
NOTE: There could be more than one correct
answer to this problem. Below is
one possibility.
$query = "select Movies.Title from Movies, Directors where
Movies.Direct_ID = Directors.ID and Directors.Name =
(select Directors.Name from Movies,
Directors where
Movies.Title =
'$movie' and Movies.Direct_ID =
Directors.ID))";
$result =
mysql_query($query);
Explanation: We are
really combining two queries into one here. In the first (inner select) we are finding the name of the
director that directed $movie. In
the second (outer select) we use the name of the director returned from the
inner select to select the movies with that director. This could also have been done with two separate
queries.
b) Consider the AJAX web programming model. What does AJAX stand for? How is it different from the "traditional" web programming model? Be specific
See Javascript Powerpoint
slides 35-38. AJAX stands for
Asynchronous Javascript And XML.
The basic idea of AJAX is that the client, through the XMLHttpRequest
object, communicates with the server asynchronously, such that submission of
data to the server and receipt of data back from the server does not require
the client page to be completely refreshed. Instead, the server sends back some incremental results (to
the XMLHttpRequest object) and the client, through DOM and Javascript, uses
that data to update the page.
2) Fill in the Blanks (10 points – 2 points each)
a)
The relationship of entities
in the Movies table to entities
in the Directors table from Part 1a)
above is ___many
to one________________ [ one-to-one,
one-to-many, many-to-one, many-to-many ].
b)
How many rows are there in a MySQL inner join of the two tables in Part 1a) above? ____12 x 5 = 60_________.
c)
The process of ______authentication______________________
is used to determine the identity of the user of a Web site, and the process of
________authorization____________________
is used to determine what a user of a Web site has access to.
d)
Javascript
variables are similar to _______PHP__________________ [Java, PHP] variables in
that both are _______dynamically_________________ [statically,
dynamically] typed.
e)
DOM stands for ________Document Object
Model_________________________________________.
3)
True or False (CORRECT any False answers) (6
points – 2 points each)
a) The primary key in a MySQL table must
be unique for each entry in the table. True
b) Javascript
scripts execute in the following
way: the .html file is downloaded
from the server to the client and a Javascript interpreter on the client's
machine executes the script. True
c) Javascript is an object-oriented
language. False – it has objects but not all OO features
4) Trace (10 points) Show the rendering of the HTML + Javascript file below, in the proper order that the output is displayed and using reasonable font approximations (by size). Show alerts as if they were regular output, putting them in the order that they occur, but draw a rectangle around them to indicate that they are alerts. Use the right side of the page for your output.
< TRACE CODE
DELETED>
|
var z = 3; alert("How about this time?"); test(z);105 302 50 84 |
5) Coding (10 points) Write a single HTML / Javascript program that will do the following:
a) Make a form that will be processed by the "processForm.php" script.
b) Ask the user to enter his / her name and year of birth and salary
i) For name and year of birth use a text input field
ii) For salary use radio buttons to give the user the choice of
(1) under 50000
(2) 50000-100000
(3) 100000-150000
(4) 150000-200000
(5) above 200000
c) When the user selects a salary, show an alert that thanks him/her for the choice.
d) When the user submits the form, check to make sure the name field has been filled and that year of birth is between 1900 and 2008. If either of these is not the case, tell the user the problem and don't let the form be submitted.
ANSWERS WILL VARY – One is given on
the next page
|
<HTML> <HEAD> <TITLE>Javascript
Quiz Code</TITLE> <SCRIPT
type = "text/javascript"> function checkData() { val
= true; if
(document.infoForm.name.value == "") { alert("You must enter your name"); document.infoForm.name.focus(); val
= false; } if
(document.infoForm.year.value < 1900 ||
document.infoForm.year.value > 2008) { alert("Your year is not in the correct range"); document.infoForm.year.focus(); val
= false; } return
val; } function thanks() { alert("Thanks
for your input"); } </SCRIPT> </HEAD> <BODY> <FORM
name = "infoForm" action = "processForm.php" method = "POST"> Name: <INPUT
type = "text" name = "name" value =
""><br /> Year
of Birth: <INPUT
type = "text" name = "year" value = ""><br
/> Salary:<br /> <INPUT
type = "radio" name = "salary" value ="1"
onClick = "thanks()">
< 50000<br /> <INPUT
type = "radio" name = "salary" value ="2"
onClick = "thanks()">
50000-100000<br /> <INPUT
type = "radio" name = "salary" value ="3"
onClick = "thanks()">
100000-150000<br /> <INPUT
type = "radio" name = "salary" value ="4"
onClick = "thanks()">
150000-200000<br /> <INPUT
type = "radio" name = "salary" value ="4"
onClick = "thanks()">
> 200000<br /> <INPUT
type = "submit" name = "Submit"> <INPUT
type = "reset" name = "Reset"> <P></P> </FORM> <SCRIPT
type = "text/javascript"> document.infoForm.onsubmit
= checkData; </SCRIPT> <HR/> </BODY> </HTML> |