I think I’m stuck and I really hope someone can help me out here.
So, I’m trying to make something like a quiz application with PHP and JS. The idea is that the user is given a picture with 4 possible answers and he has to guess what’s in that picture. User receives x points based on the answer he clicked and gets redirected to the next page, with picture and answers, and so on. There’s also a chance for user to skip to the next page. Here’s the thing though:
How do I check if the user has already answered particular question, so I could redirect him to the next page if this one has already been answered? Basically, it would be like a protection from cheating, so that the user couldn’t get more and more points from the same question.
I’m currently stuck with MySQL solution, to make column for every page, store values there and then compare them when user tries to access particular page, redirecting him based on the stored value. Is it the only solution?
I’m sorry if my english isn’t that good, and I hope you guys can understand my question. 🙂
You mentioned, that user can log in and log out. Therefore I presume, that you already have a database of users and you want to store somehow which questions were already answered by particular user, but you don’t know, what’s the proper way of storing such information into MySQL database.
Now, I am sorry if I got wrong, what you meant, but if my assumptions are correct, then there are several ways, how to store the data you want to save. You can for example add another column to the table with users, that will contain the last question that the user answered. And you can update that value everytime user answers next question.
So i.e. if you had 4 questions, the column would be empty. When you come to the page with question, you look into database, what’s the last question this user answered. Since this user didn’t answer any question thus the column is still empty, you can ask him the first question. If he answers, you can update now the column with value 1. Next time the same user accesses page with questions, you look again into database into the very same column and you will get value 1. So now you now, you’ve already asked first question and you can ask the user the next question.
In case questions are not asked in specific order and can be presented randomly, you have other possible solution: Create a reference table. You can create new table, which will contain three columns: user_id, question_id and answer to that question(if you need to save the answer too). Now everytime user opens the page that generates questions, you can look into your table with questions and select all those questions, that are not answered by the user. So you do something like this: