CogSci 3 - PHP - Part 3
Due WEDNESDAY, December 2nd, 2009 11:59pm
-Extra time has been granted due to Thanksgiving break! :-)

Goals

  1. Create a COGS3 Quiz using <form> ... </form> in XHTML. (You should have already done this.)
  2. Publish the Quiz on the web and have students take the quiz. (And this as well).
  3. Using PHP, the quiz will be corrected and statistical infomation is gathered.

Using your text editor (Notepad++ (or Taco on the Mac) , continue to work with your: grade-quiz-cg3xaa.php (The SAME file that you used in PART 2 of the assignment.)

The file should be in your public_html directory. You will be testing it from the server. So, if you are working from home, be sure to FTP the file everytime it is modified.

Before you continue, you might wish to review the trouble shooting tips given in an earlier assignment.

Comment the echo statements that you set up in Part 2. PHP has multiple ways to comment code. If you insert // (double slashes) it will ignore everything after that point on that line.

Add two variables. The $num_correct variable counts the number of correct quiz responses and $num_total is set to the total number of quiz questions.

The syntax rules for PHP variables are as follows:

You can choose your own variable names, or simply use the ones illustrated in this example.

Increment the $num_correct variable for each question when the correct answer was selected.

If, for example, your correct answer for question number 1 was option "A" then in your switch statement, "case '1a'" would be the location for you to increment $num_correct variable.

Repeat this step for each of the ten questions (switch statements) in your quiz.

Test your counter by adding this echo statement at the end of your switch statements. Make sure that you are still with in the <?php .... ?> script tags!

Save your file and test it. Make sure that EVERYTHING is working at this point before you continue.

Go back to the top of your PHP script and add two arrays. The arrays will keep track of which subject (e.g. Unix, JavaScript, Photoshop, etc.) answers are correct and incorrect.

In part 1 of the PHP assignment you were asked to write ten quiz questions --- you could select questions from the different topics covered in class.

In this assignment, you will define an "associative array" --- This is a non-sequential array that keeps track of data items using character strings (e.g. unix, Photoshop, ...) for the array indexes instead of numbers

The arrays helps one to organize data into a common list instead of working with separate variables.

For each all of the case statements in each of the switch statements, update the appropriate array values.

First you need to determine which index value to use for each question and then update either the $correct or $incorrect array index values. Actually, this would be a great use for comments. The figures don't show it, but above each 'switch' add a comment (starts with // that looks something like:

// Q1 is the UNIX question
I.e., question number followed by the content area of the question

This next section is XHTML code to display the results back to the person taking the quiz.

Add the table rows <tr> ... </tr>

Adding more rows to the table.

Add third row--- Look at the logic -- and note that it spans 3 columns; be sure to use the correct php array and index for each question.

Add row 4 - 7 for each of the quiz questions.

What you have so far.... almost there!

Comment the output text that is not associated with the table. ---

Your final output should look like this:

Good Job!! You are done!


Original Šopyright 2007, May 21, 2007 Mary ET Boyle
Modified November 2007 mrw