I am having a problem of data looping here. Basically the questions keep looping whenever there are answers for it . I am trying to display something like :
Question
Answer 1
Answer 2
Answer 3
instead of
Question
Answer 1
Question
Answer 2
Question
Answer 3
Anyone know how to solve this ?
<?php
$auctionSurvey = "SELECT questions.question_id, answers.question_id, answers.survey_id, question_body, answer_body FROM questions
INNER JOIN answers ON answers.question_id = questions.question_id
WHERE answers.survey_id='1'";
$aucResult = mysql_query($auctionSurvey) or die (mysql_error());
while ($auctionRow = mysql_fetch_assoc($aucResult)) {
echo $auctionRow['question_body'] . $auctionRow['answer_body'];
}
$questionId = 0;
while($auctionRow = mysql_fetch_assoc($aucResult)){
if($auctionRow['question_id'] != $questionId){
echo $auctionRow['question_body'];
$questionId = $auctionRow['question_id'];
}
echo $auctionRow['answer_body'];
}
Add some HTML to format it and that should work for ya.
Edit: Proof: http://ideone.com/Gkq2hd