我这里有数据循环的问题。基本上,只要有答案,问题就会不断循环。我正在尝试显示类似的内容:
Question
Answer 1
Answer 2
Answer 3
代替
Question
Answer 1
Question
Answer 2
Question
Answer 3
有人知道如何解决吗?
<?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'];
}
添加一些HTML以对其进行格式化,这应该适用于您。
编辑:证明:http://ideone.com/Gkq2hd