$userobj = json_decode($ans_user); $sysobj = json_decode($ans_sys); $count = 0; for ($uind = 0; $uind < count($userobj); $uind++) { $status = "F"; for ($sind = 0; $sind < count($sysobj); $sind++) { if ($userobj[$uind]->{'QuestionId'} == $sysobj[$sind]->{'idTestQuestions'}) { if ($userobj[$uind]->{'UserAnswer'} == $sysobj[$sind]->{'answer'}) { $status = "P"; $count++; } } } $questionId = $userobj[$uind]->{'QuestionId'}; $result = $userobj[$uind]->{'UserAnswer'}; $q->addTestResults($userId, $testId, $questionId, $result, $status); } $questionResults = $count . "/" . count($userobj); $t_json = $q->getTestDetails($testName); $t_dejson = json_decode($t_json); $totalmarks = $t_dejson[0]->{'totalmarks'}; $passMarks = $t_dejson[0]->{'passMarks'}; $totalquestions = $t_dejson[0]->{'totalquestions'}; $eachQmarks = $totalmarks / $totalquestions; $marksResults = $eachQmarks * $count; $examStatus = 'FAILED'; if ($marksResults >= $passMarks) { $examStatus = 'PASSED'; } $marksInsert = $marksResults . "/" . $totalmarks; // Results Update