error); } //*******************************daily data***************************************************************** $from_date = '\'' . date("Y-m-d",strtotime("-1 days")) . '\''; $from_time = '\'' . date("h:i:sa") . '\''; //query to get data from the table $query = "SELECT * FROM `weather` WHERE `date` > " . $from_date . " or (`time` >= " . $from_time . " and `date` >= " . $from_date . ")"; //execute query $result = $mysqli->query($query); //loop through the returned data $temp_in = ''; $temp_out = ''; $press_out = ''; $humid_out = ''; foreach ($result as $row) { $new_datapoint = '{t: \'' . $row['date'] . 'T' . $row['time'] . '+02:00\',y:' . $row['temp_in'] . '},'; $temp_in = $temp_in . $new_datapoint; $new_datapoint = '{t: \'' . $row['date'] . 'T' . $row['time'] . '+02:00\',y:' . $row['temp_out'] . '},'; $temp_out = $temp_out . $new_datapoint; $new_datapoint = '{t: \'' . $row['date'] . 'T' . $row['time'] . '+02:00\',y:' . $row['press_out'] . '},'; $press_out = $press_out . $new_datapoint; $new_datapoint = '{t: \'' . $row['date'] . 'T' . $row['time'] . '+02:00\',y:' . $row['humid_out'] . '},'; $humid_out = $humid_out . $new_datapoint; } $temp_out_d = trim($temp_out,','); $temp_in_d = trim($temp_in,','); $press_out_d = trim($press_out,','); $press_in_d = trim($press_in,','); $humid_out_d = trim($humid_out,','); $humid_in_d = trim($humid_in,','); //*******************************weekly data***************************************************************** $from_date = '\'' . date("Y-m-d",strtotime("-8 days")) . '\''; $from_time = '\'' . date("h:i:sa") . '\''; //query to get data from the table $query = "SELECT `date`, avg(`temp_out`) as temp_out FROM `weather` WHERE (`date` > " . $from_date . " or (`time` >= " . $from_time . " and `date` >= " . $from_date . ")) and time(`time`) BETWEEN '09:00:00' AND '21:00:00' group by `date`"; //execute query $result = $mysqli->query($query); $temp_out = ''; foreach ($result as $row) { $new_datapoint = '{t: \'' . $row['date'] . 'T' . '15:00:00' . 'Z\',y:' . $row['temp_out'] . '},'; $temp_out = $temp_out . $new_datapoint; } $temp_out_w_avg_dt = trim($temp_out,','); //query to get data from the table $query = "SELECT `date`, avg(`temp_out`) as temp_out FROM `weather` WHERE (`date` > " . $from_date . " or (`time` >= " . $from_time . " and `date` >= " . $from_date . ")) and (time(`time`) >= '21:00:00' OR time(`time`) <= '09:00:00') group by `date`"; //execute query $result = $mysqli->query($query); $temp_out = ''; foreach ($result as $row) { $new_datapoint = '{t: \'' . $row['date'] . 'T' . '03:00:00' . 'Z\',y:' . $row['temp_out'] . '},'; $temp_out = $temp_out . $new_datapoint; } $temp_out_w_avg_nt = trim($temp_out,','); $from_date = '\'' . date("Y-m-d",strtotime("-8 days")) . '\''; $from_time = '\'' . date("h:i:sa") . '\''; //query to get data from the table $query = "SELECT `date`, avg(`temp_in`) as temp_in, avg(`press_out`) as press_out, avg(`humid_out`) as humid_out FROM `weather` WHERE (`date` > " . $from_date . " or (`time` >= " . $from_time . " and `date` >= " . $from_date . ")) group by `date`"; //execute query $result = $mysqli->query($query); $temp_in = ''; $press_out = ''; $humid_out = ''; foreach ($result as $row) { $new_datapoint = '{t: \'' . $row['date'] . 'T' . '12:00:00' . 'Z\',y:' . $row['temp_in'] . '},'; $temp_in = $temp_in . $new_datapoint; $new_datapoint = '{t: \'' . $row['date'] . 'T' . '12:00:00' . 'Z\',y:' . $row['press_out'] . '},'; $press_out = $press_out . $new_datapoint; $new_datapoint = '{t: \'' . $row['date'] . 'T' . '12:00:00' . 'Z\',y:' . $row['humid_out'] . '},'; $humid_out = $humid_out . $new_datapoint; } $temp_in_w = trim($temp_in,','); $press_out_w = trim($press_out,','); $humid_out_w = trim($humid_out,','); //*******************************monthly data***************************************************************** $from_date = '\'' . date("Y-m-d",strtotime("-32 days")) . '\''; $from_time = '\'' . date("h:i:sa") . '\''; //query to get data from the table //$query = "SELECT * FROM `weather` WHERE `date` > " . $from_date . " or (`time` >= " . $from_time . " and `date` >= " . $from_date . ")"; $query = "SELECT `date`, avg(`temp_out`) as temp_out, avg(`press_out`) as press_out, avg(`humid_out`) as humid_out FROM `weather` WHERE (`date` > " . $from_date . " or (`time` >= " . $from_time . " and `date` >= " . $from_date . ")) group by `date`"; //execute query $result = $mysqli->query($query); //loop through the returned data $temp_out = ''; $press_out = ''; $humid_out = ''; foreach ($result as $row) { $new_datapoint = '{t: \'' . $row['date'] . 'T' . '12:00:00' . 'Z\',y:' . $row['temp_out'] . '},'; $temp_out = $temp_out . $new_datapoint; $new_datapoint = '{t: \'' . $row['date'] . 'T' . '12:00:00' . 'Z\',y:' . $row['press_out'] . '},'; $press_out = $press_out . $new_datapoint; $new_datapoint = '{t: \'' . $row['date'] . 'T' . '12:00:00' . 'Z\',y:' . $row['humid_out'] . '},'; $humid_out = $humid_out . $new_datapoint; } $temp_out_m = trim($temp_out,','); $press_out_m = trim($press_out,','); $humid_out_m = trim($humid_out,','); //*******************************yearly data***************************************************************** $from_date = '\'' . date("Y-m-d",strtotime("-366 days")) . '\''; $from_time = '\'' . date("h:i:sa") . '\''; //query to get data from the table $query = "SELECT * FROM `weather` WHERE `date` > " . $from_date . " or (`time` >= " . $from_time . " and `date` >= " . $from_date . ")"; //execute query $result = $mysqli->query($query); //loop through the returned data $temp_in = ''; $temp_out = ''; $press_out = ''; $humid_out = ''; foreach ($result as $row) { $new_datapoint = '{t: \'' . $row['date'] . 'T' . $row['time'] . 'Z\',y:' . $row['temp_in'] . '},'; $temp_in = $temp_in . $new_datapoint; $new_datapoint = '{t: \'' . $row['date'] . 'T' . $row['time'] . 'Z\',y:' . $row['temp_out'] . '},'; $temp_out = $temp_out . $new_datapoint; $new_datapoint = '{t: \'' . $row['date'] . 'T' . $row['time'] . 'Z\',y:' . $row['press_out'] . '},'; $press_out = $press_out . $new_datapoint; $new_datapoint = '{t: \'' . $row['date'] . 'T' . $row['time'] . 'Z\',y:' . $row['humid_out'] . '},'; $humid_out = $humid_out . $new_datapoint; } $temp_out_y = trim($temp_out,','); $temp_in_y = trim($temp_in,','); $press_out_y = trim($press_out,','); $humid_out_y = trim($humid_out,','); ?>