<?php
 include '../config.php';
 $data = array();
 $sql_base;
 $host_arr = array();
 $empathy_arr = array();
 $anticipate_arr = array();
 $respect_arr = array();
 $thanks_arr = array();

 $condX = $_POST['condX'];
 $conX = $_POST['conX'];
 $timeZ = $_POST['timeX'];
$tablecondX = $_POST['tablecondX'];
$columnS=array("record","Q9g",$tablecondX);
$mq=query_marge($timeZ,$columnS);
   foreach($timeZ as $key => $value)
   {
        /*host script start*/
            $columnS=array("record","Q9g","Q16_n3","Q19c1_n3","Q19e1_n3","Q35_n3","Q36_n3",$tablecondX);
            $mq=query_marge($timeZ,$columnS);
            $host=mysqli_query($conn,"SELECT avg(`Q16_n3`) FROM ($mq) AS t WHERE t.`Q9g` IN ($value) AND $condX 1=1");
            $hostV=mysqli_fetch_array($host); 
            $hostV = round($hostV[0]);
            array_push($host_arr,$hostV);
        /*host script end*/

        /*empathy script start*/
            $empathy=mysqli_query($conn,"SELECT avg(`Q19c1_n3`) FROM ($mq) AS t WHERE t.`Q9g` IN ($value) AND $condX 1=1");
            $empathyV=mysqli_fetch_array($empathy); 
            $empathyV = round($empathyV[0]);
            array_push($empathy_arr,$empathyV);
        /*empathy script end*/

        /*anticipate script start*/
            $anticipate=mysqli_query($conn,"SELECT avg(`Q19e1_n3`) FROM ($mq) AS t WHERE t.`Q9g` IN ($value) AND $condX 1=1");
            $anticipateV=mysqli_fetch_array($anticipate); 
            $anticipateV = round($anticipateV[0]);
            array_push($anticipate_arr,$anticipateV);
        /*anticipate script end*/

        /*respect script start*/
            $respect=mysqli_query($conn,"SELECT avg(`Q35_n3`) FROM ($mq) AS t WHERE t.`Q9g` IN ($value) AND $condX 1=1");
            $respectV=mysqli_fetch_array($respect); 
            $respectV = round($respectV[0]);
            array_push($respect_arr,$respectV);
        /*respect script end*/

        /*thanks script start*/
            $thanks=mysqli_query($conn,"SELECT avg(`Q36_n3`) FROM ($mq) AS t WHERE t.`Q9g` IN ($value) AND $condX 1=1");
            $thanksV=mysqli_fetch_array($thanks); 
            $thanksV = round($thanksV[0]);
            array_push($thanks_arr,$thanksV);
        /*thanks script end*/
   }
   
   $data['host'] = $host_arr;
   $data['empathy'] = $empathy_arr;
   $data['anticipate'] = $anticipate_arr;
   $data['respect'] = $respect_arr;
   $data['thanks'] = $thanks_arr;
   

 echo json_encode($data);

?>