這裏是我的PHP代碼,我從HTML中的文本框中獲取問題的值。現在,當我輸入與數據庫匹配的第二個問題時,它會回答與數據庫中的問題相匹配的答案。我希望它出現在第二行,但我不知道該怎麼做。它就像這個webapp。 http://www.simsimi.com/talk.htm如何從我的SQL中獲得第二個結果,並保留第一個結果
$question = $_POST['question'];
$sql = "select * from qa where question like '$question' order by rand() limit 1";
$dbquery = mysql_query($sql);
echo "$dbquery";
if (mysql_num_rows($dbquery)==0) {
$error = "I don\'t know. Please teach me.";
// echo "<script>";
// echo "alert('I don\'t know. Please teach me.')";
// echo "</script>";
echo "<tr>";
echo "<td align=right>$question</td>";
echo "</tr>";
echo "<tr>";
echo "<td align=left>$error</td>";
echo "</tr>";
}else{
while ($row=mysql_fetch_array($dbquery)){
$ques = $row[1];
$ans = $row[2];
echo "<tr>";
echo "<td align=right>$ques</td>";
echo "</tr>";
echo "<tr>";
echo "<td align=left>$ans</td>";
echo "</tr>";
}
這是ajax響應嗎? – 2012-03-27 09:16:33