gpt4 book ai didi

php - Join + While循环只输出一个结果

转载 作者:行者123 更新时间:2023-11-29 08:41:49 24 4
gpt4 key购买 nike

我正在尝试进行测验,并使用以下内容来比较结果,它似乎可以工作并输出一次,但这就是它的全部作用,即使有两个问题,我也没有处理更多记录测验,所以它应该输出正确、正确或正确、不正确等。

          <?php
// Make a MySQL Connection
// Construct our join query
$query = "SELECT * FROM itsnb_chronoforms_data_answerquiz a, itsnb_chronoforms_data_createquestions
q WHERE a.quizID='$quizID' AND a.userID='$userID' and q.quizID=a.quizID and
a.quizselectanswer = q.correctanswer" or die("MySQL ERROR: ".mysql_error());

$result = mysql_query($query) or die(mysql_error());


// Print out the contents of each row into a table
while($row = mysql_fetch_array($result)){
if ($row['correctanswer'] == $row['quizselectanswer']){
echo 'CORRECT';}
else { echo 'INCORRECT';
}

echo "<br />";
}
?>

编辑>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

表结构如下>>

itsnb_chronoforms_data_answer测验cf_id、cf_uid、cf_created、cf_modified、cf_ipaddress、cf_user_id、questionID、quizselectanswer、quizID、userID

itsnb_chronoforms_data_createquestionscf_id、cf_uid、cf_created、cf_modified、cf_ipaddress、cf_user_id、quizID、questionID、quizquestion、quizanswer1、quizanswer2、quizanswer3、quizanswer4、questionformat、正确答案

最佳答案

删除 selectanswer= Correctanswer 条件时,您会得到四个答案(这确实不是您想要的,因为您想要获取正确和错误的答案),因为您没有关联答案 ID。

$query = "SELECT * FROM itsnb_chronoforms_data_answerquiz a, itsnb_chronoforms_data_createquestions
q WHERE a.quizID='$quizID' AND a.userID='$userID' and q.quizID=a.quizID and
a.quizselectanswer = q.correctanswer" or die("MySQL ERROR: ".mysql_error());

应该是:

$query = "SELECT * FROM itsnb_chronoforms_data_answerquiz a, itsnb_chronoforms_data_createquestions
q WHERE a.quizID='$quizID' AND a.userID='$userID' and q.quizID=a.quizID and
a.questionID = q.questionID" or die("MySQL ERROR: ".mysql_error());

在没有该条件的情况下,您将获得 QuestionID 的叉积。您看到的四条记录(如果 QuestionID 为 1 和 2):

  1. a.questionID=1 和 q.questionID=1
  2. a.questionID=1 和 q.questionID=2(不想要这个)
  3. a.questionID=2 和 q.questionID=1(或这个)
  4. a.questionID=2 和 q.questionID=2

关于php - Join + While循环只输出一个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13588170/

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