-
Notifications
You must be signed in to change notification settings - Fork 2
/
history.php
31 lines (29 loc) · 899 Bytes
/
history.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
<?php
function delOld(){
$db = mysql_connect("localhost","datalogger","datalogger") or die("DB Connect error");
mysql_select_db("datalogger");
$q="delete from datalogger";
mysql_query($q);
mysql_close($db);
return 0;
}
function hist($sensor){
$db = mysql_connect("localhost","datalogger","datalogger") or die("DB Connect error");
mysql_select_db("datalogger");
for ($i=0;$i<=29;$i++)
{
$q= "insert into history ( ";
$q=$q."select date_add(curdate(),interval $i hour),'$sensor', round(avg(temperature),2),round(avg(humidity),2) ";
$q=$q."from datalogger ";
$q=$q."where sensor = '$sensor' ";
$q=$q."and date_time >=date_add(curdate(),interval $i hour) ";$ii=$i+1;
$q=$q."and date_time < date_add(curdate(),interval $ii hour) ";
$q=$q.") ";
mysql_query($q);
}
mysql_close($db);
return 0;
}
hist(4);
delOld();
?>