aktiv
08-06-2009, 10:52 AM
I have 2 tables for a test taking application. The first table stores the question and the answer to the question the current data is as follows.
taID---------taQuestion-----------------taCourseID---------taAnswer
127 ---------lions are insects?-------------14-----------------2
126 ---------ants are brown and black?----14-----------------1
125--------- ants are insects?-------------14-----------------1
Just an FYI, for taAnswer 2 = false 1 = true
Now I have the table for the answers being recorded, it looks like this:
ansID---------ansCID---------ansUID---------ansQuesID---------ansAnswer
220------------14--------------1----------------125--------------2
219------------14--------------1----------------126--------------1
218------------14--------------1----------------127--------------1
Now if you compare the answers that are correct in the first table to the second table just above you can see that only 1 answer is correct which is #126 (taID in table 1 and ansQuesID in table 2).
My problem is the query I currently have is not working, my current query looks like this:
$cid = is simply a $_GET call
$uid = simply checking the $_SESSION
SELECT taID, taQuestion, taCourseID, taAnswer, answers.ansID, answers.ansCID, answers.ansUID, count(answers.ansQuesID) as correct,answers.ansAnswer
FROM testAnswers join answers on ansQuesID=taID
WHERE taCourseID = $cid AND answers.ansUID = $uid
GROUP BY taID
Any Advice?
taID---------taQuestion-----------------taCourseID---------taAnswer
127 ---------lions are insects?-------------14-----------------2
126 ---------ants are brown and black?----14-----------------1
125--------- ants are insects?-------------14-----------------1
Just an FYI, for taAnswer 2 = false 1 = true
Now I have the table for the answers being recorded, it looks like this:
ansID---------ansCID---------ansUID---------ansQuesID---------ansAnswer
220------------14--------------1----------------125--------------2
219------------14--------------1----------------126--------------1
218------------14--------------1----------------127--------------1
Now if you compare the answers that are correct in the first table to the second table just above you can see that only 1 answer is correct which is #126 (taID in table 1 and ansQuesID in table 2).
My problem is the query I currently have is not working, my current query looks like this:
$cid = is simply a $_GET call
$uid = simply checking the $_SESSION
SELECT taID, taQuestion, taCourseID, taAnswer, answers.ansID, answers.ansCID, answers.ansUID, count(answers.ansQuesID) as correct,answers.ansAnswer
FROM testAnswers join answers on ansQuesID=taID
WHERE taCourseID = $cid AND answers.ansUID = $uid
GROUP BY taID
Any Advice?