我的數據庫包含問題和答案。問題有一個ID(intQAID),並且響應有一個ID(intResponseID)。 intRespondID與它所響應的intQAID ID相同。數據庫中的每個條目都有自己的ID,即intPostID。聲明幫助(PHP)
我想要做的是寫一個查詢,將抓住所有這些信息並使用while語句將其發佈到網站。但是,在while循環結束之前,結構必須是問題,並且是下面的答案。
我可以得到問題後:
$question = mysql_query("SELECT *,
(SELECT cUsername FROM tblUsers tblU WHERE Q2.intPosterID = tblU.intUserID) AS username,
(SELECT DATE_FORMAT(dPostDateTime, '%b %e %Y %H:%i')) AS post_time
FROM tblQA Q2 WHERE intResponseID = 0
ORDER BY Q2.dSortDateTime DESC, Q2.intQAID DESC LIMIT 40");
while($row = mysql_fetch_array($question))
{
echo "<tr class='forum'>";
echo "<td class='forum'>" . substr($row['cBody'], 0, 150) . "</td>";
echo "<td class='forum'>" . $row['cCategory'] . "</td>";
echo "<td class='forum'>" . $row['username'] . "</td>";
echo "<td class='forum'>" . $row['post_time'] . "</td>";
echo "</tr>";
}
但我怎麼能得到它後,答案在同一個while語句?
應該輸出像這樣:
Question 1:
Answer 1:
Question 2:
Answer 2:
Question 3:
Answer 3:
etc....
逃離你的輸出! – 2012-03-28 21:46:40
每個問題總是一個答案嗎? – 2012-03-28 21:48:02
請停止使用古老的'mysql_ *'函數 – 2012-03-28 21:48:25