I have a MySQL Database for a basic quiz program I’m making. The questions table is as follows:
ID | quiz_ID | QuestionNumber | Question |
1 | 1 | 1 | What is 5 + 5? |
2 | 1 | 2 | What is 12 - 4? |
3 | 1 | 3 | Whats the square root of 25? |
4 | 2 | 1 | What is the centre of an atom called? |
5 | 2 | 2 | What is the nucleus made up of? |
What I need to happen is if $quiz_ID in my PHP equals 2, and $qn (which is the question number) equals 1, then it should display “What is the centre of an atom called?” And then I should be able to increment $qn and that should display the next question in that quiz. I just need some of the basic PHP code to enable me to do this.
So far, I can get it to find out how many questions are in each quiz (with a query), and then loop through them, but this only works for the very first quiz (quiz_ID = 1) I need it to be able to work with what ever quiz the user selected.
I also have 2 more tables, for quizzes and answers that are linked to this table, and when (if i ever get there) this program is up and running there will be loads more entries than there is in the example above, so I need to find a pretty solid algorithm thats going to work.
Thanks in advance, I am so grateful to you guys on this website – when I’m a bit better at PHP I will contribute and answer questions.
Thanks!
For getting all the questions under the given quiz: