Hi I have a problem I have my question for example saved with two answers correct, but when i take the test and i click just one correct, it takes as correct. I want to do it when I don't click both answers as correct to show wrong answer, only when I click both to show correct.
foreach($answers as $answer){
$correct_answer = Answer::where('id', $answer)->where('correct', 1)->where('deleted',0)->get();
if(count($correct_answer) == 1){
$answer_result = 1;
}else{
$answer_result = 0;
}
$results[$answer] = $answer_result;
}
}else{
//if test hasn't any answer selected than all answers are wrong
$questions = Question::where('test_id', $test_id)->where('deleted',0)->get();
foreach($questions as $question){
$answers = Answer::where('question_id', $question->id)->where('deleted',0)->get();
foreach($answers as $answer){
$results[] = 0;
}
}
}
Aucun commentaire:
Enregistrer un commentaire