<?php

/*Student API*/

/*Fetching API*/

/* Attempt to connect to MySQL database */
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'restax');

define('DB_PASSWORD', 'restax@123');

define('DB_NAME', 'Restax'); 

$con = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);

$course_id = $request->getAttribute('course_id');
$paper_shortcode = $request->getAttribute('paper_shortcode');
$exam_id = $request->getAttribute('exam_id');

if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$response=array();

if(isset($course_id)){

$sql="SELECT * FROM pwe_answersheet_submit WHERE course_id='$course_id' AND exams_id='$exam_id' AND papers_shortcode='$paper_shortcode'  ORDER BY id DESC";
$result=mysqli_query($con,$sql);

if ($result->num_rows > 0) {
	
while($row=mysqli_fetch_assoc($result)){
    $exams_id=$row['exams_id'];
    $registernumberlist=$row['roll_number'];
    $scorelist=$row['score'];
    $gradelist=$row['Grade'];
    $status=$row['status'];
    $state=$row['state'];

$data[]=array(
'students'=>$registernumberlist,
'score'=>$scorelist,
'grade' =>$gradelist,
'status'=>$status,
'state'=>$state
);
}
echo json_encode($data);
}
else{
	$response=array('status' => "false",'Message' => "Grade Students count not found..!");
         echo json_encode(array($response));
}
}
?>