我有兩個要運行的查詢。結果應該是,困難/問題行列在問題下面的答案中。答案雖然通過JavaScript隱藏,直到我選擇按圖像按鈕,然後應顯示屬於所選問題的答案。子查詢返回多於1行錯誤
代碼:
$result = mysqli_query($mysqli,"SELECT rid, pid, qid, aid, points FROM result WHERE rid=$val");
$answertext = mysqli_query($mysqli, "SELECT answer FROM answer_det WHERE pid=(SELECT pid FROM result WHERE rid=$val) AND qid=(SELECT qid FROM result WHERE rid=$val) AND aid=(SELECT aid FROM result WHERE rid=$val)");
while($row = mysqli_fetch_array($result) AND $row2 = mysqli_fetch_array($answertext))
{
$resultp = $row['points'];
$color = "#000000";
if (($resultp >= 1) && ($resultp <= 3))
$color = "#FF0000";
else if (($resultp >= 3) && ($resultp <= 6))
$color = "#FF9900";
else if (($resultp >= 6) && ($resultp <= 10))
$color = "#07d407";
echo "<div class='question-wrap'>
<b><small>Dilemma ".$row['qid']." - Answer ". $row['aid'].": </small><span style=\"color: $color\">". $resultp."</span></b> of <b>10 <small>Points</small></b>
<input type='image' class='answer-toggle' title='Information' src='img/down.png' width='13' height='10'>
<p class='answer'>". $row2['answertext']."</p></div>"; }
我無法弄清楚什麼是錯的。這是我得到的消息:
Warning: mysqli_query(): (21000/1242): Subquery returns more than 1 row in D:\home\site\wwwroot\devlopment\respondent2.php on line 122 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in D:\home\site\wwwroot\devlopment\respondent2.php on line 125
這是行122:
$answertext = mysqli_query($mysqli, "SELECT answer FROM answer_det WHERE pid=(SELECT pid FROM result WHERE rid=$val) AND qid=(SELECT qid FROM result WHERE rid=$val) AND aid=(SELECT aid FROM result WHERE rid=$val)");
這是行125:
while($row = mysqli_fetch_array($result) AND $row2 = mysqli_fetch_array($answertext))
** WARNING **:當使用'mysqli',你應該使用參數化查詢和['bind_param'](http://php.net/manual/en/mysqli-stmt.bind-param.php)將用戶數據添加到您的查詢。 **不要**使用字符串插值或連接來完成此操作,因爲您將創建嚴重的[SQL注入漏洞](http://bobby-tables.com/)。 **絕不**將'$ _POST'數據直接放入查詢中。 – tadman