<?php

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

$paper = $request->getAttribute('paper');
$slot=$request->getAttribute('slot');



$response=array();

///students
if ($students=="") {
  $students="0";
 }
 if ($present=="") {
  $present="0";
 }
 if ($absent=="") {
  $absent="0";
 }
 if ($malpractice=="") {
  $malpractice="0";
 }
 
///STUDENT

if(isset($paper)&&isset($slot)){
$sql=("SELECT roll_number  from submit_answer_script  WHERE paper=$paper AND slot=$slot");
}

elseif(isset($paper)){
$sql=("SELECT roll_number  from submit_answer_script  WHERE paper=$paper");
}

else{
$sql=("SELECT roll_number  from submit_answer_script ");
}
$result=mysqli_query($con,$sql);

    while ($row1[]=mysqli_fetch_assoc($result)) {  

      $students=count($row1);

	}
	
	

///PRESENT

if(isset($paper)&&isset($slot)){
$sql=("SELECT status  from submit_answer_script  WHERE status='present' AND  paper=$paper AND slot=$slot");
}

elseif(isset($paper)){
$sql=("SELECT status  from submit_answer_script  WHERE status='present' AND  paper=$paper");
}

else{
$sql=("SELECT status  from submit_answer_script where status='present'");
}
$result=mysqli_query($con,$sql);

    while ($row2[]=mysqli_fetch_assoc($result)) {  

      $present=count($row2);

	}

///ABSENT

if(isset($paper)&&isset($slot)){
$sql=("SELECT status  from submit_answer_script  WHERE status='absent' AND  paper=$paper AND slot=$slot");
}

elseif(isset($paper)){
$sql=("SELECT status  from submit_answer_script  WHERE status='absent' AND  paper=$paper");
}

else{
$sql=("SELECT status  from submit_answer_script where status='absent'");
}
$result=mysqli_query($con,$sql);

    while ($row3[]=mysqli_fetch_assoc($result)) {  

      $absent=count($row3);

	}

///MALPRACTICE

if(isset($paper)&&isset($slot)){
$sql=("SELECT status  from submit_answer_script  WHERE status='malpractice' AND  paper=$paper AND slot=$slot");
}

elseif(isset($paper)){
$sql=("SELECT status  from submit_answer_script  WHERE status='malpractice' AND  paper=$paper");
}

else{
$sql=("SELECT status  from submit_answer_script where status='malpractice'");
}
$result=mysqli_query($con,$sql);

    while ($row4[]=mysqli_fetch_assoc($result)) {  

      $malpractice=count($row4);

	}

	
	
	
	
echo '[{"students":"'.$students.'","present":"'.$present.'","absent":"'.$absent.'","malpractice":"'.$malpractice.'"}]';

?>