so i’m writing a simple quiz script: user gets list of questions and has 2 possible answers.
i have 2 tables:
1) containing user id and question id
user | question_id
2) containing questions database, with answers, number of votes for each answer and if qiven question is accepted (can be viewed on public list)
id | question | answer1 | answer2 | a1count | a2count | accept
I have a problem with my sql statement – now i wrote this (user id is constant atm):
(User should get only those questions which havent been answered yet)
SELECT *
FROM questions as q, answers as a
WHERE a.user = 2
AND a.question_id <> q.id
AND q.accept = 1
and if result of this has 0 rows i put and if statement to retrieve all possible questions.
Unfortunatelly at some point it went wrong: When i answered all questions first statement gets 0 rows and next statement is triggered + how to check show unanswered questions when the 1st table is empty and has nothing to compare with?
mayby anyone can give a hint or help how to solve this? thx in advance!
I am assuming instead of q.accept = 1 it should be q.accept = 0 (accept = 1 (answered) and accept = 0 (unanswered))
You can get through non existence by using this query