forked from Jahislove/Hargassner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_conso_90j.php
45 lines (33 loc) · 1.39 KB
/
json_conso_90j.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
// appelé par ajax, renvoi les series de data pour toutes les saisons
require_once("conf/config.inc.php");
header("Content-type: text/json");
// recupere la conso des 90 derniers jours
$query0 = "SELECT dateB,conso,Tmoy FROM consommation
ORDER BY dateB DESC LIMIT 90";
// recupere le prix de la saison en cours
$query1 = "SELECT * FROM tarif
ORDER BY saison DESC LIMIT 1" ;
$conn = mysqli_connect ($hostname, $username, $password, $database);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$req0 = mysqli_query($conn, $query0);
$req1 = mysqli_query($conn, $query1);
mysqli_close($conn);
// #########traitement query1######################################################################################
$data = mysqli_fetch_row($req1);
$prix = $data[1];
while($data = mysqli_fetch_row($req0)){
$dateD = strtotime($data[0]) * 1000;
$chart1_data1[] = [$dateD, $data[1]];//kg
$chart1_data2[] = [$dateD, $data[2]];//temperature
$cout = round($data[1]*$prix,1,PHP_ROUND_HALF_EVEN);
$chart1_data3[] = [$dateD, $cout];//cout
}
$chart1_data1 = array_reverse($chart1_data1);
$chart1_data2 = array_reverse($chart1_data2);
$chart1_data3 = array_reverse($chart1_data3);
$tableau = [$chart1_data1,$chart1_data2,$chart1_data3];
echo json_encode($tableau, JSON_NUMERIC_CHECK);
?>