<?php

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

$course_id = $request->getAttribute('course_id');
$exams_id = $request->getAttribute('exams_id');
$date = $request->getAttribute('date');
$time = $request->getAttribute('time');

$response=array();
if(isset($course_id)&&isset($exams_id)&&isset($date)&&isset($time)){
  $sql="SELECT  papers_shortcode, roll_number, course_id, exams_id, date, time
  FROM pwi_submit
    WHERE pwi_submit.process=2 AND pwi_submit.course_id='$course_id' AND pwi_submit.exams_id='$exams_id' AND pwi_submit.date='$date' AND pwi_submit.time='$time' ";
    }

elseif(isset($course_id)&&isset($exams_id)&&isset($date)){
  $sql="SELECT  papers_shortcode, roll_number, course_id, exams_id, date, time
  FROM pwi_submit
    WHERE pwi_submit.process=2 AND pwi_submit.course_id='$course_id' AND pwi_submit.exams_id='$exams_id' AND pwi_submit.date='$date' ";
    }

elseif(isset($course_id)&&isset($exams_id)){
  $sql="SELECT  papers_shortcode, roll_number, course_id, exams_id, date, time
  FROM pwi_submit
    WHERE pwi_submit.process=2 AND  pwi_submit.course_id='$course_id' AND pwi_submit.exams_id='$exams_id' ";
    }

elseif(isset($course_id)){
$sql="SELECT  papers_shortcode, roll_number, course_id, exams_id, date, time
 FROM pwi_submit
WHERE process=2 AND course_id='$course_id' ";
}

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

while ($row=mysqli_fetch_assoc($result)) {

$stud=$row['roll_number'];
$pap=$row['papers_shortcode'];
$stud_array=json_decode($stud, true);
$paper=json_decode($pap, true);

$i=0;
foreach( $stud_array as $stud_roll ) {
    
   $user = $stud_roll;
   
 $response[] = $user;
  $r1=count($response);

      $pap = array_unique($paper);
       $response2[] = $pap; 
        $r2=count($pap);

 $i=$i+1;

}
}

$count=array([
    'students'=>$r1, 'paper'=>$r2    
    ]);

echo json_encode($count);

?>






