I have a working survey that pulls each question and any related answers from multiple tables. Each question is stored in the following table:
- tblQuestions, with the fields:
- qID
- qText.
The related answers are stored in the table:
- tblPossAnswers, with the fields:
- aID
- qID
- answerText.
So, I would have 3 possible answers for each question. My sql to pull everything is:
select * from tblQuestions, tblPossAnswers where
tblPossAnswers.qID = tblQuestions.qID
order by tblQuestions.qID ASC
And my PHP to display it:
while ($row = mysql_fetch_array($result)) {
echo "<p>" . $row['qText'] . "</p><br />";
echo "<input type='radio' name='".$row['qID']."' value='".$row['aID']."' />";
echo $row['answerText'];
}
The problem is this is displaying the qText every time it displays a possible answer. So it looks like:
- Question 1
- Possible answer 1
- Question 1
- Possible answer 2
- Question 1
- Possible answer 3
- Question 2
- Possible answer 1
- Question 2
- Possible answer 2
- Question 2
- Possible answer 3
What I would like to do is have the qText only display when the first possible answer is pulled. I'm still somewhat of a newb to MySQL, so the solution might be something very simple that I'm just not seeing.