<?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');


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

$response=array();

if(isset($course_id)){

$sql="SELECT exams_id,papers_shortcode,slot FROM pwi_submit WHERE 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($exams_id,$examname,$name,$slotlist[$i]);
 echo json_encode($array_dashboard);
  $i = $i+1;  
}
   
}


}



// $sql="SELECT  set_grade.set_grade_id,set_grade.course_id,set_grade.dept_id,set_grade.level_id,set_grade.range_in,set_grade.grade,department.dept_shortcode,level.level_shortcode  FROM set_grade INNER JOIN department ON department.dept_id = set_grade.dept_id INNER JOIN level ON level.level_id = set_grade.level_id WHERE course_id = '$course_id'AND dept_id = '$dept_id'";


//$result=mysqli_query($con,$sql);

  //  while ($row[]=mysqli_fetch_assoc($result)) {  

 //     $user=$row;

//      $array1 = array("5","26","38","42");

// $array2 = array("15","36","38","42");

//      $user = array_intersect($array1, $array2);



   // }
// foreach ($user as &$value) {
//     $intersect[] = $value;

//        $providers = array_intersect($intersect[$value]);

// }
      // echo json_encode($course_id);
      // echo json_encode($dept_id);


//echo json_encode($user);

?>