PDA

View Full Version : mySQL query problem


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?

Fumigator
08-06-2009, 06:27 PM
My problem is the query I currently have is not working, my current query looks like this:

Not working... as in, your computer melts into a puddle of liquid plastic when the query runs? Or, not working as in your query creates a wormhole?

Give us the error message at least.

Old Pedant
08-06-2009, 09:28 PM
No place there do you actually check to see if the value of TestAnswers.taAnswer matches the value of answers.ansAnswer.

Your JOIN is *ONLY* matchine on the question, *NOT* also on the answers.

aktiv
08-07-2009, 09:54 AM
thanks guys here is the code select count(*) from table1
join table2 on table1.taID=table2.ansQuesID AND table1.taAnswer=table2.ansAnswer