<?php
 include '../config.php';
$data = array();
$sql_base;

$condX = $_POST['condX'];
$conX = $_POST['conX'];
$timeZ = $_POST['timeX'];
$paper_arr = array();
$Q26A_1_arr = array();
$Q26A_2_arr = array();
$Q26A_3_arr = array();
$Q26B_1_arr = array();
$Q26B_2_arr = array();
$Q26B_3_arr = array();
$Q26C_arr= array();
$Q26D_arr= array();
$Q26E_arr= array();
$Q26N_arr = array();
$tablecondX = $_POST['tablecondX'];
$columnS=array("record","Q9g",$tablecondX);
$mq=query_marge($timeZ,$columnS);
 $poor="1,2,3,4";
 $average="5,6";
 $Outstanding="7,8,9,10";
   foreach($timeZ as $key => $value)
   {
    $Q23V_arr = array();
      if($conX==1)
      {    
         $condX="";   
         $q=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN ($value) ");
         $baseX=mysqli_fetch_array($q);
         $base=$baseX[0];
      }
     if($conX==2)
      {
         
         $q=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN ($value) AND $condX 1=1");
         $baseX=mysqli_fetch_array($q);
         $base=$baseX[0];
      }

      $sql_base = $base;
      if($sql_base==0)
      {
        array_push($Q26A_1_arr,0);
        array_push($Q26A_2_arr,0);
        array_push($Q26A_3_arr,0);
        array_push($Q26B_1_arr,0);
        array_push($Q26B_2_arr,0);
        array_push($Q26B_3_arr,0);
        array_push($Q26C_arr,0);
        array_push($Q26D_arr,0);
        array_push($Q26E_arr,0);
        array_push($Q26N_arr,0);
      }
      else
      {
          $columnS=array("record","Q9g","Q26",$tablecondX);
            $mq=query_marge($timeZ,$columnS);
         $q26N=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN ($value) AND $condX t.`Q26` in (1,2,3,4,5,6,7,8) ");
		$Q26N=mysqli_fetch_array($q26N); 
		$Q26NV = round(($Q26N[0]/$sql_base )* 100,1);
		array_push($Q26N_arr,$Q26NV);
		
        /*Q26a script start*/
        $columnS=array("record","Q9g","Q26a",$tablecondX);
            $mq=query_marge($timeZ,$columnS);
        $q26a_1=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN ($value) AND $condX t.`Q26a` in (1) ");
        $Q26a_1=mysqli_fetch_array($q26a_1); 
        $Q26A_1 = round(($Q26a_1[0] / $sql_base ) * 100,1);
        array_push($Q26A_1_arr,$Q26A_1);

        $q26a_2=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN ($value) AND $condX t.`Q26a` in (2) ");
        $Q26a_2=mysqli_fetch_array($q26a_2); 
        $Q26A_2 = round(($Q26a_2[0] / $sql_base ) * 100,1);
        array_push($Q26A_2_arr,$Q26A_2);

        $q26a_3=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN ($value) AND $condX t.`Q26a` in (3) ");
        $Q26a_3=mysqli_fetch_array($q26a_3); 
        $Q26A_3 = round(($Q26a_3[0] / $sql_base ) * 100,1);
        array_push($Q26A_3_arr,$Q26A_3);

        /*Q26a script end*/
        
        
        
        
        /*Q26b script start*/
        $columnS=array("record","Q9g","Q26","Q26b",$tablecondX);
            $mq=query_marge($timeZ,$columnS);
        $q26b_base=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN ($value) AND $condX t.`Q26` in (1,2,3,4,5,6,7,8) ");
        $Q26b_base=mysqli_fetch_array($q26b_base); 
        $data['Q26b_base'] = $Q26b_base;
        
        $q26b_1=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN ($value) AND $condX t.`Q26b` in (1) ");
        $Q26b_1=mysqli_fetch_array($q26b_1); 
        $Q26B_1 = round(($Q26b_1[0] / $sql_base ) * 100,1);
        array_push($Q26B_1_arr,$Q26B_1);

        $q26b_2=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN ($value) AND $condX t.`Q26b` in (2) ");
        $Q26b_2=mysqli_fetch_array($q26b_2); 
        $Q26B_2 = round(($Q26b_2[0] / $sql_base ) * 100,1);
        array_push($Q26B_2_arr,$Q26B_2);

        $q26b_3=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN ($value) AND $condX t.`Q26b` in (3) ");
        $Q26b_3=mysqli_fetch_array($q26b_3); 
        $Q26B_3 = round(($Q26b_3[0] / $sql_base ) * 100,1);
        array_push($Q26B_3_arr,$Q26B_3);

        /*Q26a script end*/
        
        
        
        /*Q26c script start*/
        $columnS=array("record","Q9g","Q26c",$tablecondX);
            $mq=query_marge($timeZ,$columnS);
        $q26c=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN ($value) AND $condX t.`Q26c` in (1) ");
        $Q26c=mysqli_fetch_array($q26c); 
        $Q26C = round(($Q26c[0] / $sql_base ) * 100,1);
        array_push($Q26C_arr,$Q26C);
        /*Q26c script end*/
        
        
        
        /*Q26d script start*/
        $columnS=array("record","Q9g","Q26d",$tablecondX);
            $mq=query_marge($timeZ,$columnS);
        $q26d=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN ($value) AND $condX t.`Q26d` in (1) ");
        $Q26d=mysqli_fetch_array($q26d); 
        $Q26D = round(($Q26d[0] / $sql_base ) * 100,1);
        array_push($Q26D_arr,$Q26D);
        /*Q26d script end*/
        
        
        
        /*Q26e script start*/
        $columnS=array("record","Q9g","Q26e",$tablecondX);
            $mq=query_marge($timeZ,$columnS);
        $q26e=mysqli_query($conn,"SELECT COUNT(`record`) FROM ($mq) AS t WHERE t.`Q9g` IN ($value) AND $condX t.`Q26e` in (1) ");
        $Q26e=mysqli_fetch_array($q26e); 
        $Q26E = round(($Q26e[0] / $sql_base ) * 100,1);
        array_push($Q26E_arr,$Q26E);
        /*Q26e script end*/
      }
        /*paperSSI script start*/
        $columnS=array("record","Q9g","Q26_n1",$tablecondX);
            $mq=query_marge($timeZ,$columnS);
            $paperSSI=mysqli_query($conn,"SELECT avg(`Q26_n1`) FROM ($mq) AS t WHERE t.`Q9g` IN ($value) AND $condX 1=1");
            $paperSSIV=mysqli_fetch_array($paperSSI); 
            $paperSSIV2 = round($paperSSIV[0]);
            array_push($paper_arr,$paperSSIV2);
        /*paperSSI script end*/
        
   }

    $data['overallpaper'] = $paper_arr;
    $data['Q26A_1'] = $Q26A_1_arr;
    $data['Q26A_2'] = $Q26A_2_arr;
    $data['Q26A_3'] = $Q26A_3_arr;
    $data['Q26B_1'] = $Q26B_1_arr;
    $data['Q26B_2'] = $Q26B_2_arr;
    $data['Q26B_3'] = $Q26B_3_arr;
    $data['Q26C'] = $Q26C_arr;
    $data['Q26D'] = $Q26D_arr;
    $data['Q26E'] = $Q26E_arr;
    $data['Q26N'] = $Q26N_arr;
  
    echo json_encode($data);

?>
























