function arrayToJSON($array) { if ($array) { $result = array(); $resultDict = array(); $isDict = false; $index = 0; foreach ($array as $key => $value) { if ($key != $index++) { $isDict = true; } if (is_array($value)) { $value = arrayToJSON($value); } else { if (!is_numeric($value) or $key == 'name') { $value = '"' . washJS($value) . '"'; } } $result[] = $value; $resultDict[] = '"' . washJS($key) . '":' . $value; } if ($isDict) { return '{' . implode($resultDict, ',') . '}'; } else { return '[' . implode($result, ',') . ']'; } } else { return '[]'; } }
function arrayToJSON($array) { $json = '{ '; foreach ($array as $key => $value) { $json .= '"' . $key . '" : '; if (is_array($value)) { $json .= arrayToJSON($value); } else { // Make sure to strip backslashes and convert things to // entities in our output $json .= '"' . scrub_out(str_replace('\\', '', $value)) . '"'; } $json .= ' , '; } $json = rtrim($json, ', '); return $json . ' }'; }
<?php include 'redis_config.php'; include 'arrayToJSON.php'; if (isset($_POST['user'])) { $data = $redis->LRANGE($key, 0, 30); $newData = arrayToJSON($data); echo $newData; }
include_once "../db/db.php"; function arrayToJSON($array = array()) { if (is_array($array)) { array_walk_recursive($array, function (&$value) { $value = utf8_encode($value); }); } return json_encode($array); } $sqlCriterio = "SELECT * FROM pessoas"; if (isset($_GET["filter"])) { $filters = json_decode($_GET["filter"]); $sqlCriterio .= " WHERE"; foreach ($filters as $filter) { $sqlCriterio .= " {$filter->property} LIKE '%{$filter->value}%' AND "; } $sqlCriterio = substr($sqlCriterio, 0, -5) . " ORDER BY id DESC"; } if (isset($_GET["start"]) && is_numeric($_GET["start"])) { $sqlLimite = $sqlCriterio . " LIMIT " . $_GET["limit"]; } if (isset($_GET["limit"]) && is_numeric($_GET["limit"])) { $sqlLimite .= " OFFSET " . $_GET["start"]; } $retorno = []; $retorno["pessoas"] = $mysqli->query($sqlLimite)->fetch_all(); $retorno["total"] = $mysqli->query($sqlCriterio)->num_rows; echo arrayToJSON($retorno);
function getValues() { if (isset($_POST['foi']) and isset($_POST['startdate']) and isset($_POST['enddate']) and isset($_POST['outliers'])) { // If argument is set, use it (temperature or humidity $numarg = func_num_args(); if ($numarg == 1) { $obs = array(func_get_arg(0)); } else { // else use the observation if (isset($_POST['observation'])) { $obs = $_POST['observation']; //If no checkboxes (except: PM10) are checked, obs = 0 } else { $obs = 0; } } // number of arguments (offering_ids) $numargs = count($obs); // rows - temp-array (db-results) $rows = array(); // cols - column informaton for the json object $cols = array(); // Get all time_stamps of all observations of one foi between start- and enddate $timestamp = getTimeStamp($_POST['foi'], $_POST['startdate'], $_POST['enddate']); if ($_POST['outliers'] == 'yes') { //1, 2, 3, 4 additional parameters? switch ($numargs) { // 1 additional parameter - obs1 case 1: $obs1 = $obs['0']; // Get the observation values $rows = getObservationValues($_POST['foi'], $_POST['startdate'], $_POST['enddate'], $obs1); // Set the columns $cols = array(array('label' => 'date', 'type' => 'string'), array('label' => gerColNames($obs1), 'type' => 'number')); // required for $rows - see below $j = 0; //if available insert the values for ($i = 0; $i < count($timestamp); $i++) { $ttime = $timestamp[$i]; $temp = array(); $temp[] = array('v' => $ttime['time_stamp']); if ($j < count($rows)) { $row = $rows[$j]; // case 1 - all observation values if ($row['time_stamp'] == $ttime['time_stamp']) { if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $row['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs1, $row['numeric_value'])); } $j++; } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } // save the result to $trows and delete $temp $trows[] = array('c' => $temp); unset($temp); } //to JSON and return $table $table = arrayToJSON($cols, $trows); echo $table; break; // 2 additional parameter - obs1, obs2 // 2 additional parameter - obs1, obs2 case 2: $obs1 = $obs['0']; $obs2 = $obs['1']; //Get the observation values $rows = getObservationValues($_POST['foi'], $_POST['startdate'], $_POST['enddate'], $obs1, $obs2); //Set the columns $cols = array(array('label' => 'date', 'type' => 'string'), array('label' => gerColNames($obs1), 'type' => 'number'), array('label' => gerColNames($obs2), 'type' => 'number')); //required for $rows - see below $j = 0; $k = 0; //if available insert the values for ($i = 0; $i < count($timestamp); $i++) { $ttime = $timestamp[$i]; $temp = array(); $temp[] = array('v' => $ttime['time_stamp']); if ($j < count($rows)) { $row = $rows[$j]; // case 2 - obs1 if ($row['offering_id'] == $obs1) { if ($ttime['time_stamp'] == $row['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $row['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs1, $row['numeric_value'])); } $j++; if ($j < count($rows)) { $row = $rows[$j]; } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } // case 2 - obs2 if ($row['offering_id'] == $obs2) { if ($ttime['time_stamp'] == $row['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $row['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs2, $row['numeric_value'])); } $j++; } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); $temp[] = array('v' => null); } //save the result to $trows and delete $temp $trows[] = array('c' => $temp); unset($temp); } //to JSON and return table $table = arrayToJSON($cols, $trows); echo $table; break; // 3 additional parameters - obs1, obs2, obs3 // 3 additional parameters - obs1, obs2, obs3 case 3: $obs1 = $obs['0']; $obs2 = $obs['1']; $obs3 = $obs['2']; //Get the observation values $rows = getObservationValues($_POST['foi'], $_POST['startdate'], $_POST['enddate'], $obs1, $obs2, $obs3); //Set the columns $cols = array(array('label' => 'date', 'type' => 'string'), array('label' => gerColNames($obs1), 'type' => 'number'), array('label' => gerColNames($obs2), 'type' => 'number'), array('label' => gerColNames($obs3), 'type' => 'number')); //required for $rows - see below $j = 0; $k = 0; //if available insert the values for ($i = 0; $i < count($timestamp); $i++) { $ttime = $timestamp[$i]; $temp = array(); $temp[] = array('v' => $ttime['time_stamp']); if ($j < count($rows)) { $row = $rows[$j]; //case 3 - obs1 if ($row['offering_id'] == $obs1) { if ($ttime['time_stamp'] == $row['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $row['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs1, $row['numeric_value'])); } $j++; if ($j < count($rows)) { // Get next row $row = $rows[$j]; } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } //case 3 - obs2 if ($row['offering_id'] == $obs2) { if ($ttime['time_stamp'] == $row['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $row['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs2, $row['numeric_value'])); } $j++; if ($j < count($rows)) { // Get next row $row = $rows[$j]; } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } //case 3 - obs3 if ($row['offering_id'] == $obs3) { if ($ttime['time_stamp'] == $row['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $row['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs3, $row['numeric_value'])); } $j++; } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); $temp[] = array('v' => null); $temp[] = array('v' => null); } //save the result to $trows and delete $temp $trows[] = array('c' => $temp); unset($temp); } //to JSON and return table $table = arrayToJSON($cols, $trows); echo $table; break; // 4 additional parameters - obs1, obs2, obs3, obs4 // 4 additional parameters - obs1, obs2, obs3, obs4 case 4: $obs1 = $obs['0']; $obs2 = $obs['1']; $obs3 = $obs['2']; $obs4 = $obs['3']; //Get the observation values $rows = getObservationValues($_POST['foi'], $_POST['startdate'], $_POST['enddate'], $obs1, $obs2, $obs3, $obs4); //Set the columns $cols = array(array('label' => 'date', 'type' => 'string'), array('label' => gerColNames($obs1), 'type' => 'number'), array('label' => gerColNames($obs2), 'type' => 'number'), array('label' => gerColNames($obs3), 'type' => 'number'), array('label' => gerColNames($obs4), 'type' => 'number')); //required for $rows - see below $j = 0; //if available insert the values for ($i = 0; $i < count($timestamp); $i++) { $ttime = $timestamp[$i]; $temp = array(); $temp[] = array('v' => $ttime['time_stamp']); if ($j < count($rows)) { $row = $rows[$j]; //case 4 - obs1 if ($row['offering_id'] == $obs1) { if ($ttime['time_stamp'] == $row['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $row['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs1, $row['numeric_value'])); } $j++; if ($j < count($rows)) { // Get next row $row = $rows[$j]; } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } //case 4 - obs2 if ($row['offering_id'] == $obs2) { if ($ttime['time_stamp'] == $row['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $row['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs2, $row['numeric_value'])); } $j++; if ($j < count($rows)) { // Get next row $row = $rows[$j]; } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } //case 4 - obs3 if ($row['offering_id'] == $obs3) { if ($ttime['time_stamp'] == $row['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $row['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs3, $row['numeric_value'])); } $j++; if ($j < count($rows)) { // Get next row $row = $rows[$j]; } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } //case 4 - obs4 if ($row['offering_id'] == $obs4) { if ($ttime['time_stamp'] == $row['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $row['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs4, $row['numeric_value'])); } $j++; } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); $temp[] = array('v' => null); $temp[] = array('v' => null); $temp[] = array('v' => null); } //save the result to $trows and delete $temp $trows[] = array('c' => $temp); unset($temp); } //to JSON and return table $table = arrayToJSON($cols, $trows); echo $table; break; } } /* -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- * -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- * -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- * -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- */ if ($_POST['outliers'] == 'no') { //1, 2, 3, 4 or 5 additional parameters? switch ($numargs) { // 1 additional parameter - obs1 case 1: $obs1 = $obs['0']; // Get the observation values $rows = getObservationValues($_POST['foi'], $_POST['startdate'], $_POST['enddate'], $obs1); $rowsY = getObservationValuesYes($_POST['foi'], $_POST['startdate'], $_POST['enddate'], $obs1); // Set the columns $cols = array(array('label' => 'date', 'type' => 'string'), array('label' => gerColNames($obs1), 'type' => 'number'), array('label' => 'Ausreisser_' . shortOffName($obs1), 'type' => 'number')); // required for $rows - see below $j = 0; $k = 0; //if available insert the values for ($i = 0; $i < count($timestamp); $i++) { $ttime = $timestamp[$i]; $temp = array(); $temp[] = array('v' => $ttime['time_stamp']); if ($j < count($rows)) { $row = $rows[$j]; // case 1 - all observation values if ($row['time_stamp'] == $ttime['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $row['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs1, $row['numeric_value'])); } $j++; } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } if ($k < count($rowsY)) { $rowY = $rowsY[$k]; // case 1 - outliers only if ($rowY['time_stamp'] == $ttime['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $rowY['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs1, $rowY['numeric_value'])); } $k++; } else { $temp[] = array('v' => null); } //j >= count($rows) } else { $temp[] = array('v' => null); } // save the result to $trows and delete $temp $trows[] = array('c' => $temp); unset($temp); } //to JSON and return $table $table = arrayToJSON($cols, $trows); echo $table; break; // 2 additional parameter - obs1, obs2 // 2 additional parameter - obs1, obs2 case 2: $obs1 = $obs['0']; $obs2 = $obs['1']; //Get the observation values $rows = getObservationValues($_POST['foi'], $_POST['startdate'], $_POST['enddate'], $obs1, $obs2); $rowsY = getObservationValuesYes($_POST['foi'], $_POST['startdate'], $_POST['enddate'], $obs1, $obs2); //Set the columns $cols = array(array('label' => 'date', 'type' => 'string'), array('label' => gerColNames($obs1), 'type' => 'number'), array('label' => gerColNames($obs2), 'type' => 'number'), array('label' => 'Ausreisser_' . shortOffName($obs1), 'type' => 'number'), array('label' => 'Ausreisser_' . shortOffName($obs2), 'type' => 'number')); //required for $rows - see below $j = 0; $k = 0; //if available insert the values for ($i = 0; $i < count($timestamp); $i++) { $ttime = $timestamp[$i]; $temp = array(); $temp[] = array('v' => $ttime['time_stamp']); if ($j < count($rows)) { $row = $rows[$j]; // case 2 - obs1 if ($row['offering_id'] == $obs1) { if ($ttime['time_stamp'] == $row['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $row['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs1, $row['numeric_value'])); } $j++; if ($j < count($rows)) { $row = $rows[$j]; } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } // case 2 - obs2 if ($row['offering_id'] == $obs2) { if ($ttime['time_stamp'] == $row['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $row['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs2, $row['numeric_value'])); } $j++; } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); $temp[] = array('v' => null); } if ($k < count($rowsY)) { // Get next row $rowY = $rowsY[$k]; // case 2 - obs1 (outliers) if ($rowY['offering_id'] == $obs1) { if ($ttime['time_stamp'] == $rowY['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $rowY['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs1, $rowY['numeric_value'])); } $k++; if ($k < count($rowsY)) { $rowY = $rowsY[$k]; } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } // case 2 - obs2 (outliers) if ($rowY['offering_id'] == $obs2) { if ($ttime['time_stamp'] == $rowY['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $rowY['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs2, $rowY['numeric_value'])); } $k++; } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); $temp[] = array('v' => null); } //save the result to $trows and delete $temp $trows[] = array('c' => $temp); unset($temp); } //to JSON and return table $table = arrayToJSON($cols, $trows); echo $table; break; // 3 additional parameters - obs1, obs2, obs3 // 3 additional parameters - obs1, obs2, obs3 case 3: $obs1 = $obs['0']; $obs2 = $obs['1']; $obs3 = $obs['2']; //Get the observation values $rows = getObservationValues($_POST['foi'], $_POST['startdate'], $_POST['enddate'], $obs1, $obs2, $obs3); $rowsY = getObservationValuesYes($_POST['foi'], $_POST['startdate'], $_POST['enddate'], $obs1, $obs2, $obs3); //Set the columns $cols = array(array('label' => 'date', 'type' => 'string'), array('label' => gerColNames($obs1), 'type' => 'number'), array('label' => gerColNames($obs2), 'type' => 'number'), array('label' => gerColNames($obs3), 'type' => 'number'), array('label' => 'Ausreisser_' . shortOffName($obs1), 'type' => 'number'), array('label' => 'Ausreisser_' . shortOffName($obs2), 'type' => 'number'), array('label' => 'Ausreisser_' . shortOffName($obs3), 'type' => 'number')); //required for $rows - see below $j = 0; $k = 0; //if available insert the values for ($i = 0; $i < count($timestamp); $i++) { $ttime = $timestamp[$i]; $temp = array(); $temp[] = array('v' => $ttime['time_stamp']); if ($j < count($rows)) { $row = $rows[$j]; //case 3 - obs1 if ($row['offering_id'] == $obs1) { if ($ttime['time_stamp'] == $row['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $row['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs1, $row['numeric_value'])); } $j++; if ($j < count($rows)) { // Get next row $row = $rows[$j]; } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } //case 3 - obs2 if ($row['offering_id'] == $obs2) { if ($ttime['time_stamp'] == $row['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $row['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs2, $row['numeric_value'])); } $j++; if ($j < count($rows)) { // Get next row $row = $rows[$j]; } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } //case 3 - obs3 if ($row['offering_id'] == $obs3) { if ($ttime['time_stamp'] == $row['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $row['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs3, $row['numeric_value'])); } $j++; } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); $temp[] = array('v' => null); $temp[] = array('v' => null); } if ($k < count($rowsY)) { $rowY = $rowsY[$k]; //case 3 - obs1 (outliers) if ($rowY['offering_id'] == $obs1) { if ($rowY['time_stamp'] == $ttime['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $rowY['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs1, $rowY['numeric_value'])); } $k++; if ($k < count($rowsY)) { // Get next row $rowY = $rowsY[$k]; } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } //case 3 - obs2 (outliers) if ($rowY['offering_id'] == $obs2) { if ($rowY['time_stamp'] == $ttime['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $rowY['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs2, $rowY['numeric_value'])); } $k++; if ($k < count($rowsY)) { // Get next row $rowY = $rowsY[$k]; } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } //case 3 - obs3 (outliers) if ($rowY['offering_id'] == $obs3) { if ($rowY['time_stamp'] == $ttime['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $rowY['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs3, $rowY['numeric_value'])); } $k++; } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); $temp[] = array('v' => null); $temp[] = array('v' => null); } //save the result to $trows and delete $temp $trows[] = array('c' => $temp); unset($temp); } //to JSON and return table $table = arrayToJSON($cols, $trows); echo $table; break; // 4 additional parameters - obs1, obs2, obs3, obs4 // 4 additional parameters - obs1, obs2, obs3, obs4 case 4: $obs1 = $obs['0']; $obs2 = $obs['1']; $obs3 = $obs['2']; $obs4 = $obs['3']; //Get the observation values $rows = getObservationValues($_POST['foi'], $_POST['startdate'], $_POST['enddate'], $obs1, $obs2, $obs3, $obs4); $rowsY = getObservationValuesYes($_POST['foi'], $_POST['startdate'], $_POST['enddate'], $obs1, $obs2, $obs3, $obs4); //Set the columns $cols = array(array('label' => 'date', 'type' => 'string'), array('label' => gerColNames($obs1), 'type' => 'number'), array('label' => gerColNames($obs2), 'type' => 'number'), array('label' => gerColNames($obs3), 'type' => 'number'), array('label' => gerColNames($obs4), 'type' => 'number'), array('label' => 'Ausreisser_' . shortOffName($obs1), 'type' => 'number'), array('label' => 'Ausreisser_' . shortOffName($obs2), 'type' => 'number'), array('label' => 'Ausreisser_' . shortOffName($obs3), 'type' => 'number'), array('label' => 'Ausreisser_' . shortOffName($obs4), 'type' => 'number')); //required for $rows - see below $j = 0; $k = 0; //if available insert the values for ($i = 0; $i < count($timestamp); $i++) { $ttime = $timestamp[$i]; $temp = array(); $temp[] = array('v' => $ttime['time_stamp']); if ($j < count($rows)) { $row = $rows[$j]; //case 4 - obs1 if ($row['offering_id'] == $obs1) { if ($ttime['time_stamp'] == $row['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $row['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs1, $row['numeric_value'])); } $j++; if ($j < count($rows)) { // Get next row $row = $rows[$j]; } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } //case 4 - obs2 if ($row['offering_id'] == $obs2) { if ($ttime['time_stamp'] == $row['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $row['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs2, $row['numeric_value'])); } $j++; if ($j < count($rows)) { // Get next row $row = $rows[$j]; } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } //case 4 - obs3 if ($row['offering_id'] == $obs3) { if ($ttime['time_stamp'] == $row['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $row['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs3, $row['numeric_value'])); } $j++; if ($j < count($rows)) { // Get next row $row = $rows[$j]; } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } //case 4 - obs4 if ($row['offering_id'] == $obs4) { if ($ttime['time_stamp'] == $row['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $row['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs4, $row['numeric_value'])); } $j++; } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); $temp[] = array('v' => null); $temp[] = array('v' => null); $temp[] = array('v' => null); } if ($k < count($rowsY)) { $rowY = $rowsY[$k]; //case 4 - obs1 (outliers) if ($rowY['offering_id'] == $obs1) { if ($rowY['time_stamp'] == $ttime['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $rowY['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs1, $rowY['numeric_value'])); } $k++; if ($k < count($rowsY)) { $rowY = $rowsY[$k]; } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } //case 4 - obs2 (outliers) if ($rowY['offering_id'] == $obs2) { if ($rowY['time_stamp'] == $ttime['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $rowY['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs2, $rowY['numeric_value'])); } $k++; if ($k < count($rowsY)) { $rowY = $rowsY[$k]; } } else { //if ttime ['time_stamp'] != $rowY['time_stamp] $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } //case 4 - obs3 (outliers) if ($rowY['offering_id'] == $obs3) { if ($rowY['time_stamp'] == $ttime['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $rowY['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs3, $rowY['numeric_value'])); } $k++; if ($k < count($rowsY)) { $rowY = $rowsY[$k]; } } else { //if ttime ['time_stamp'] != $rowY['time_stamp] $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } //case 4 - obs4 (outliers) if ($rowY['offering_id'] == $obs4) { if ($rowY['time_stamp'] == $ttime['time_stamp']) { // Calc ppm-Values, if Station is set to Geist or Weseler if ($_POST['foi'] != "Geist" and $_POST['foi'] != "Weseler") { $temp[] = array('v' => $rowY['numeric_value']); } else { $temp[] = array('v' => calcToPPM($obs4, $rowY['numeric_value'])); } $k++; if ($k < count($rowsY)) { $rowY = $rowsY[$k]; } } else { //if ttime ['time_stamp'] != $rowY['time_stamp] $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); } } else { $temp[] = array('v' => null); $temp[] = array('v' => null); $temp[] = array('v' => null); $temp[] = array('v' => null); } //save the result to $trows and delete $temp $trows[] = array('c' => $temp); unset($temp); } //to JSON and return table $table = arrayToJSON($cols, $trows); echo $table; break; } } // unset all vars unset($cols); unset($rows); unset($table); unset($row); unset($trows); unset($timestamp); unset($ttime); unset($obs); unset($outliers); unset($j); unset($k); } else { // "" if no offering_ids are chosen echo '""'; } }