gpt4 book ai didi

php - 子查询返回多于 1 行错误

转载 作者:行者123 更新时间:2023-11-29 06:16:04 24 4
gpt4 key购买 nike

我有两个要运行的查询。结果应该是困境/问题的行与问题下方的答案一起列出。答案会被 javascript 隐藏,直到我选择按下图像按钮,然后它应该会显示属于所选问题的答案。

代码:

$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))

最佳答案

当你使用像这样的查询时

WHERE your_column = (SELECT ... WHERE ...)

子选择必须只返回一行;如果没有,那么您会收到所看到的错误。

一个快速的解决方案可能是将其更改为

WHERE your_column = (SELECT ... WHERE ... LIMIT 1)

但我会改用联接:

SELECT answer
FROM answer_det
JOIN result USING (pid, qid, aid)
WHERE result.rid = $val

关于php - 子查询返回多于 1 行错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35873953/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com