<?php

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

$course_id=$request->getAttribute('course_id');
$exams_id=$request->getAttribute('exams_id');
$response=array();

if(isset($course_id)&&isset($exams_id)){
    $sql="SELECT pwi_submit.course_id, pwi_submit.exams_id, pwi_submit.papers_shortcode, course.course_name, Exams.examname FROM pwi_submit
    INNER JOIN course ON course.course_id=pwi_submit.course_id
INNER JOIN Exams ON Exams.id=pwi_submit.exams_id
WHERE pwi_submit.course_id='$course_id' AND pwi_submit.exams_id='$exams_id' AND pwi_submit.process=2 ";
}
elseif(isset($course_id)){
$sql="SELECT pwi_submit.course_id, pwi_submit.exams_id,  pwi_submit.papers_shortcode, course.course_name, Exams.examname FROM pwi_submit
INNER JOIN course ON course.course_id=pwi_submit.course_id
INNER JOIN Exams ON Exams.id=pwi_submit.exams_id
WHERE pwi_submit.course_id='$course_id' AND pwi_submit.process=2 ";
}
$result=mysqli_query($con, $sql);

while($row=mysqli_fetch_assoc($result)){
    $user1['course_name']=$row['course_name'];
    $user1['examname']=$row['examname'];
    $user1['course_id']=$row['course_id'];
    $user1['exams_id']=$row['exams_id'];
    $user3=$row['papers_shortcode'];
    $user=json_decode($user3, true);
   
   $a=array_unique($user);

    
    foreach($a as $pap){
        $user1['papers_shortcode']=$pap;
        
    $response[]=$user1;
   
    }
}
 echo json_encode($response);

?>