PHP如果是mysqli查询语句

时间:2016-07-26 10:08:58

标签: php mysql sql mysqli

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

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

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";
  }
}

我知道我在这里犯了一个基本或愚蠢的错误,所以任何帮助都会受到赞赏。

2 个答案:

答案 0 :(得分:1)

//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";
}

答案 1 :(得分:0)

你忘了mysqli_query("")

if ($result4 = mysqli_query($con, "SELECT * FROM submissions where teamID='$teamName' and questionID='$data[0]' and status='correct'")) {
  echo "Answered";
} else {
  echo "Not Answered";
}