<?php

/*Student API*/


/*Fetching API*/



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

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


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

$response=array();

if(isset($course_id)){

$sql="SELECT  pwi_submit.paper,pwi_submit.course_id,pwi_submit.season_id,pwi_submit.file_path,pwi_submit.exams_id,pwi_submit.papers_shortcode,pwi_submit.slot,pwi_submit.id,Exams.examname FROM pwi_submit INNER JOIN Exams ON Exams.id = pwi_submit.exams_id WHERE pwi_submit.course_id='$course_id'  ORDER BY id DESC";
$result=mysqli_query($con,$sql);
while($row=mysqli_fetch_assoc($result)){
//     $roll_number=$row['papers_shortcode'];
//     $exams_id=$row['exams_id'];
//     $slot=$row['slot'];
//     $slotlist=json_decode($slot,true);
// $example = json_decode($row['papers_shortcode'], true);

// $sql="SELECT * FROM Exams WHERE id='$exams_id'";
// $result=mysqli_query($con,$sql);
// while($row=mysqli_fetch_assoc($result)){
//     $examname=$row['examname'];

// }
// $i=0;
// foreach( $example as $name ) {
// $array_dashboard=array('exam_id'=>$exams_id,'exam_name'=>$examname,'papers_shortcode'=>$name,'slot'=>$slotlist[$i]);
// $array_dashboard1[]=$array_dashboard;
//   $i = $i+1;  
// }

$get_exams_id = $row['exams_id'];
$get_course_id = $row['course_id'];
$get_season_id = $row['season_id'];

$get_file_path = $row['file_path'];

 $get_papers_shortcode = json_decode($row['papers_shortcode']);
$last_papers_shortcode = array_unique($get_papers_shortcode);

 $get_paper = json_decode($row['paper']);
$last_paper = array_unique($get_paper);

$get_slot = json_decode($row['slot']);
$last_slot = array_unique($get_slot);

$get_id = $row['id'];
$get_examname = $row['examname'];

$array_dashboard[] = array('course_id'=>$get_course_id,'season_id'=>$get_season_id,'exam_id'=>$get_exams_id,'exam_name'=>$get_examname,'papers_shortcode'=>$last_papers_shortcode,'slot'=>$last_slot,'id'=>$get_id,'paper'=>$last_paper,'file_path'=>$get_file_path);



   
}

 echo json_encode($array_dashboard);


}


?>