Each candidate will have the question and the answer. For example, I have 10 questions. Each candidate will have 10 questions and each question will have answer to it of the candidate.
Thanks
What I don't know is how will I link the table. For example, I have created a candidate, I want the newly created candidate to have all the questions linked to him from questions and answers page and vice versa.
To return all questions and answers associated with each candidate, for all the candidates, the SQL would be:
Code:
SELECT c.*, q.*, a.* FROM (( candidates c LEFT JOIN questions q ON q.candidate_id = c.id ) LEFT JOIN answers a ON a.question_id = q.id ) ORDER BY c.last_name
To return all questions and answers associated with each candidate, for all the candidates, the SQL would be:
Code:
SELECT c.*, q.*, a.* FROM (( candidates c LEFT JOIN questions q ON q.candidate_id = c.id ) LEFT JOIN answers a ON a.question_id = q.id ) ORDER BY c.last_name
A friend of mine recommended me to use sessions instead of SQL. He told me that the long query is the wrong method.
Can you elaborate how can I use sessions and avoid this long query?
I assumed you were storing this information in database tables (MySQL was my assumption). If that's the case, you will need SQL to retrieve the information from the database, sessions will not do that for you.
I believe what your friend is referring to is long query strings in the url, something like quiz.php?candidate=1&question=364&answer=1285. In which case, sessions would be useful.
That SQL I posted is not passed in the url, but is part of your php code.
When I insert a new question(through a form), I want to add the question(iterate) for every candidate in candidates table therefore, it would need to update the candidate_id to every question. How will I achieve this?
Well, I'm not sure what you're asking. There's no reason to add the question for everyone. You just need to store the question(w/possible answers), and the user(w/their answer).
Well, I'm not sure what you're asking. There's no reason to add the question for everyone. You just need to store the question(w/possible answers), and the user(w/their answer).
There is no possible answer. The answer is of the candidate and that's the correct answer in both(true or false condition).