gpt4 book ai didi

PHP if mysqli查询语句

转载 作者:行者123 更新时间:2023-11-28 23:27:43 25 4
gpt4 key购买 nike

我正在创建一个显示一组问题的网站,但我的问题是检查用户是否回答了问题,如果回答了,则显示“已回答”标签。

但是目前,每个问题都会显示“已回答”标签,即使答案不在提交表中也是如此。任何帮助将不胜感激。

while($data = mysqli_fetch_row($result)){
if($data[0] != null){
echo('
<div class="col-md-4 col-sm-5">
<div class="panel panel-default text-center">
<div class="panel-heading">
<span class="fa-stack fa-5x">
<i class="fa fa-circle fa-stack-2x text-default"></i>
<i class="fa fa-codepen fa-stack-1x fa-inverse"></i>
</span>
</div>
<div class="panel-body">
');
if($result4 = mysqli_query($mysqli,"SELECT * FROM submissions where teamID='$teamName' and questionID='$data[0]' and status='correct'")){
echo "Answered";
} else{
echo "Not Answered";
}

echo ('
<h4>'.$data[6].' - <small><i>'.$data[8].' points</i></small></h4>
<p>'.$data[7].'</p>
<a href="question.php?id='.$data[0].'" class="btn btn-primary btn-block">View Question </a>
</div>
</div>
</div>
');} else{
echo "No More Questions";
}
}

我知道我在这里犯了一个基本或愚蠢的错误,因此感谢您的帮助。

最佳答案

//Mysql query to find number of answers for particular question.
$answercount = mysqli_query($mysqli, "SELECT * FROM submissions where teamID='$teamName' and questionID='$data[0]' and status='correct'");
$answercount = mysqli_num_rows($answercount);

//PHP code
if($answercount>0){
echo "Answered";
} else{
echo "Not Answered";
}

关于PHP if mysqli查询语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38586948/

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