zero-perfoliate
zero-perfoliate

Author Topic: Using php to score a simple spelling test  (Read 318 times)

Offline uncledave

  • New PHP Members
  • Posts: 1
  • Karma: +0/-0
Using php to score a simple spelling test
« on: February 07, 2009, 01:22:06 PM »
Hi everyone,

I'm new here, so I might just introduce myself first. I'm Dave, a teacher in Sydney who teaches new arrivals to Australia to speak English.

I have a very simple quiz here ( http://www.tesolclassroom.com/compspelquiz001.html ) which asks students to identify 10 pieces of computer hardware.

I've set up the php code such that each answer is imported directly into a Mysql database (See my code below).

I've got this part working with no problems. Basically each question from 1 to 10 is labelled '$q001' to '$q010', and these correspond with database cells of the same names ( 'q001' to 'q010' ).

However... I also have another cell for each question which is the same name, but with 'score' appended to the end ( ie: 'q001score' to 'q010score' ).

Is it possible to send a value of '1' to each of these score cells if the student spells the piece of hardware correctly, or a value of '0' to each of these score cells if the word is not spelt this way?

Ie: The first answer is a 'mouse'. If the student spells it correctly (case sensitive), I'd like the value '1' sent to cell q001score, and if they spell it any other way (or leave it blank), a '0' would be sent to this cell?  Similarly, the second answer is 'monitor', and I'd like a '1' sent to cell q002score if it is spelt as such, or a '0' sent to this cell if it is spelt any other way.

The second part of my question relates to adding these scores. The final cell in my Mysql database is entitled 'totalscore'. Is it possible to add the numbers from cells '001score' to '010score' to put a total in this final cell?

Thanks for your time,

Dave


Code: [Select]

$query = "INSERT INTO compspelquiz001 (firstname, lastname, class, q001, q002, q003, q004, q005, q006, q007, q008, q009, q010)" . "VALUES ('$firstname', '$lastname', '$class', '$q001', '$q002', '$q003', '$q004', '$q005', '$q006', '$q007', '$q008', '$q009', '$q010')";
//if($query){echo 'data has been placed'}
mysql_query($query) or die(mysql_error());
mysql_close($con);









Offline PhPHelper

  • http://Digiscapers.com
  • Full Member
  • PHP Problem Solvers
  • ****
  • Posts: 179
  • Karma: +50/-0
    • Bad Apple Mail
Re: Using php to score a simple spelling test
« Reply #1 on: February 10, 2009, 05:11:16 PM »
yes you can do an if statement to check the values

Code: [Select]
//check if correct
if ($q001 == $q001score)
{
//question is right give value of 1
$q1 = 1;
} else {
//question is wrong give value of 0
$q1 = 0;
}

Then add the values together:

Code: [Select]

$total = $q001 + $q002 + $q003 + $q004 + $q005 + $q006 + $q007 + $q008 + $q009 + $q010;