davidcriniti Posted February 7, 2009 Share Posted February 7, 2009 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 feel I should also disclose that I've also asked this question on another similar forum. ( http://www.phphelpforum.com/index.php ). I apologise if that's not 'the done thing'. I guess I'm just trying to find the best source of help and at this stage I don't know one forum from the other....anyway...to my question: 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 $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); Link to comment https://forums.phpfreaks.com/topic/144251-using-php-to-score-a-simple-spelling-test/ Share on other sites More sharing options...
Mchl Posted February 7, 2009 Share Posted February 7, 2009 Yes it all is possible (yay!) But before we go into details: the way you designed your database is not optimal. Imagine you want to add questions to your test, or change them. Or add another test that all students have to take as well. All these situations would require you to change your table structure. You should normalize your database (we have a sticky in MySQL part of forums, where you can read about that). It might seem a bit complicated (and unnecessary) at first, but in reality it is not. I think there's this saying: 'A nick in time, saves nine'. That's the case here. Link to comment https://forums.phpfreaks.com/topic/144251-using-php-to-score-a-simple-spelling-test/#findComment-757033 Share on other sites More sharing options...
davidcriniti Posted February 8, 2009 Author Share Posted February 8, 2009 hmm...you're certainly right about it seeming complicated. I hope you're right about the "at first" bit too, and it grows easier with time! Link to comment https://forums.phpfreaks.com/topic/144251-using-php-to-score-a-simple-spelling-test/#findComment-757349 Share on other sites More sharing options...
Mchl Posted February 8, 2009 Share Posted February 8, 2009 It's all about creating database objects (student, test, question, answer) and relations between them (assign student to test, assign question to test, assign answer to student and question). Link to comment https://forums.phpfreaks.com/topic/144251-using-php-to-score-a-simple-spelling-test/#findComment-757360 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.