I have a query below where a user will type in a term from a question and it will output questions which contains that term and with it, it will display associated with the question it’s answer, its option type, it’s reply type etc.
Below is the query:
SELECT DISTINCT q.QuestionContent, o.OptionType, q.NoofAnswers,
GROUP_CONCAT(DISTINCT Answer SEPARATOR '') AS Answer,
r.ReplyType, q.QuestionMarks, q.SessionId
FROM Answer an
JOIN Question q
ON q.QuestionId = an.QuestionId
AND an.SessionId = q.SessionId
JOIN Reply r
ON q.ReplyId = r.ReplyId
JOIN Option_Table o
ON q.OptionId = o.OptionId
WHERE ".implode(" AND ", array_fill(0, $numTerms, "q.QuestionContent LIKE ?"))."
GROUP BY an.SessionId, an.QuestionId
Now I realise that by using CRON, every year it will delete previous Exams (SessionId) meaning that these questions will not appear for the user to search in the user.
So what I wanted to do was set up a table where it stores all previous questions, the table is below:
Previous_Question Table:
PreviousId (auto) PreviousContent
1 What is 2+2?
2 What is 4+4 and 3+3?
3 What is square root of 144?
So I want to use the Previous_Question Table to be able to search for previous questions. so I need to change query above The biggest problem though is that this table does not link to any other table, meaning that how am I going to be able to retrieve it’s correct Answer, Reply Type, Option Type etc? This is my problem.
Any help?
EDIT:
Below are the other tables:
Question Table
SessionId QuestionId QuestionContent NoofAnswers ReplyId QuestionMarks OptionId
AAA 1 What is 2+2? 1 1 5 2
AAA 2 What is 4+4 and 3+3? 1 2 5 3
ABC 3 What is square root of 144? 1 1 7 5
Answer Table:
AnswerId(auto) SessionId QuestionId Answer
1 AAA 1 B
2 AAA 2 A
3 AAA 3 D
4 ABC 1 A
Reply Table:
ReplyId ReplyType
1 Single
2 Multiple
Option Table:
OptionId OptionType
1 A-C
2 A-D
3 A-E
4 A-F
5 A-G
Now lets say that SessionId “AAA” get deleted, that means all of the corresponding rows which contains “AAA” for SessionId in “Question” table will be deleted. But just realised that so would the corresponding answers.
I need to help on somehow set up something where it will store previous questions and its details (Answers, Reply Type, Option Type) etc so that even though questions and answers are deleted because their session has been deleted, that the teacher can some how pick out those questions which are stored somewhere so the teacher can still be selecting those questions and their relevant answers, options type, reply type etc.
Quick shot… you can either change the structure of your session table and add a bool field, let’s say “active”. Then, run a query over that table, and set active to TRUE.
And, instead of delete the session, just change the value to inactive. So next time when you need to, just check if active=TRUE.