-1
I have a bank of questions organized as follows:
questions:
ID | pergunta | a | b | c | d | e | correta
1 | Qual meu nome? | joao | pedro | jose | mateus | lucas | pedro
2 | Qual a minha idade? | 15 | 18 | 20 | 22 | 25 | 18
When the user accesses your profile page, a random question from this database should appear to him. However, questions he has already hit in the past should not appear again.
For this, I tried to create a new table that related the questions to the user, as in the example below:
cad_questoes:
id_tabela | id_questao | id_usuario | acerto
1 | 1 | 2 | sim
2 | 2 | 2 | nao
3 | 1 | 1 | sim
To ask the question to the database that will be shown to the user, I use the following command in PHP/Mysql:
$busca_questoes = "SELECT * FROM cad_questoes
INNER JOIN questoes ON cad_questoes.id_questao = questoes.ID
WHERE acerto='nao' ORDER BY rand() LIMIT 1";
However, for this command to work in practice, I would have to update the cad_questoes database manually to notify that there are questions that have not been answered, but I would like this to be done automatically.
My question is: How to request a question from the database that the user has not answered it and how to do this check?
I hope you have made yourself clear, I am willing to provide any information that contributes to the question.
About creating a cad_questoes.answered column, what would be the difference for the existing cad_questoes.acerto column? On the other suggestion, what would be the benefit of knowing the response of other users and how would this prevent repeated questions from appearing to the user in question? Thanks for the comments!
– Pedro Schimmelpfeng
@Pedroschimmelpfeng from what I understood from his schema, the column
cq.acerto
guard whether the user got the question right or not, what I suggested is to save whether he already answered it or not. Maybe it wasn’t clear, but I thought that all users would answer the same questions, which is why I told to ask a query searching all questions that the logged in user did not answer.– fajuchem
you’re right, but I wanted to avoid having to create a new line for each user created, as you mentioned... Even why would I also have to do this for every new question I entered into the database, no?
– Pedro Schimmelpfeng