我在這裏遇到數據循環的問題。基本上,只要有答案,問題就會持續循環。我想顯示是這樣的:來自MYSQL數據庫的數據循環
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'];
}
因爲這是如何'JOIN's工作。如果您的數據在表格A和表格B之間以n:m關係進行映射,那麼您將擁有n個B數據副本,m個副本數據和n * m個總行數。你必須用PHP編寫邏輯來處理它。 – Sammitch