Problem Retaining Radio Button Selection

Hi all. I'm doing a page for multiple choice questions. The question and answer choice are in two separate database tables (question and answer). The layout of the page is like this:

Question 1
Answer choice (4 or 2 radio buttons)

Question 2
Answer choice (4 or 2 radio buttons)

...and so on. Managed this part with the help from people here too (link) but I overlooked what was going on with the radio buttons. I was doing the code for points calculation and couldn't get the no. of correct answers.

This code below currently detects all the radio buttons (answers for differet questions) as one group. When I select an answer for question 2 it takes away answer for question 1, same goes for question 2 when answering question 3. I tried putting the q_id value as the button value (line 41) hoping that would somewhat distinguish the buttons but it didn't work.

I've searched for this problem again and found a help from this post (link). I added an array to answer in line 7. I can select more than one radio button now but for some reason can only do so for either of the three questions.

For example, when I answer the questions in order, when I get to question 4 and select the answer, the selection I made question 1 disappears. Can anyone point me in the right direction? Thanks.

However, you seem to be running many queries, I'd suggest a JOINed sql so that you retrieve the question data and the answer data in one query. If you ORDER BY q_id, then all answers will be grouped with the question. You just create a new question in HTML when the value of q_id changes. Just one approach though.

As for the JOIN sql, won't the code output the questions multiple times depending on the iteration of the radio buttons if I queried them at once?

I also tried this query below but as you can see it only displays the answers.

SELECT a_id, a_text, a_value FROM answer
JOIN question ON question.q_id=answer.q_id
ORDER BY q_id

Am I missing something here?

That php-derived html is difficult to follow. Why so many tables? You seem tot be creating a new table for every answer.

Were you referring to the POINTS CALCULATION code? What I intend to do is insert student response for each question into the eval_set table (after accumulating the correct response) hence the INSERT INTO in the while loop. The result table only holds the overall result (ie total of correct response). I haven't had the chance to test the code because of the radio button problem.