0

When I run the query it returns all the correct values except it doesn't return any values where a.Correct = null (i.e a quiz question hasn't been answered at all), but it does return values for a.Correct = 0.

 /***Configure the retest***/
    public function CreateRetest($topicID) {
    $retestData = array();
    $count = 0;

    $createSQL = "SELECT q.QuestionID,q.Question,q.Answer,q.TopicID From quizanswered a RIGHT JOIN question q ON a.QuestionID = q.QuestionID where (a.Correct=null OR a.Correct = 0) AND q.TopicID = '$topicID'";
    $create = mysqli_query($this->db,$createSQL) or die(mysqli_connect_errno()."Cannot create tables");
    while($row = mysqli_fetch_array($create)){
    $rQuestionID = $row['QuestionID'];
    $rQuestion = $row['Question'];
    $rAnswer = $row['Answer'];
    $retestData[$count] = array($rQuestionID,$rQuestion,$rAnswer);
    $count +=1;
    }
    return $retestData;

 }
Kurt Görg
  • 15
  • 3
  • Your question is not related to PHP. remove the PHP tag and all PHP code and keep **only** the sql query – Dekel Dec 07 '16 at 01:59

1 Answers1

0

Replace the =null with IS NULL

SELECT 
    q.QuestionID,
    q.Question,
    q.Answer,
    q.TopicID 
FROM quizanswered a 
RIGHT JOIN question q 
ON a.QuestionID = q.QuestionID 
WHERE (a.Correct IS NULL OR a.Correct = 0) AND q.TopicID = '$topicID'
Bob Lukens
  • 700
  • 6
  • 10