<?php

$con = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
$paper_id = $request->getAttribute('paper_id');
$response=array();


//paper start query
$sql = "SELECT papers_id,course_id,season_id,exams_id FROM assign_papers WHERE id = $paper_id";

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



while($row = mysqli_fetch_assoc($result)){
    $data = json_decode($row['papers_id']);
    $course_id = $row['course_id'];
    $season_id = $row['season_id'];
    $exams_id = $row['exams_id'];
    
    foreach($data as $datas)
    {
       $sql_getpaper = "SELECT set_papers.papers_id,set_papers.papers_shortcode,set_papers.paper_name,set_papers.credits,schedule_exam.date,schedule_exam.time,set_marks.max_marks FROM set_papers INNER JOIN schedule_exam ON schedule_exam.paper_id = set_papers.papers_id AND schedule_exam.course_id = '$course_id' AND schedule_exam.season_id = '$season_id' AND schedule_exam.exams_id = '$exams_id' INNER JOIN set_marks ON set_marks.course_id = schedule_exam.course_id AND set_marks.season_id = schedule_exam.season_id AND set_marks.exams_id = schedule_exam.exams_id AND set_marks.paper = schedule_exam.paper_id  WHERE set_papers.papers_id = '$datas'";
       $result_paper = mysqli_query($con,$sql_getpaper);
       while($rowdata =mysqli_fetch_assoc($result_paper))
       {
           $paper_data[] = $rowdata;
       }
    }
  
}

echo json_encode($paper_data);
?>