-
Notifications
You must be signed in to change notification settings - Fork 0
/
device2_stats.php
94 lines (86 loc) · 3.14 KB
/
device2_stats.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
$title = 'Smart Home | Appliance 1 Statistics';
include $_SERVER["DOCUMENT_ROOT"].'/home/core/init.php';
f_protect_page();
include $_SERVER["DOCUMENT_ROOT"].'/home/includes/overall/header.php';
?>
<div class="container">
<div class="row">
<center><h2>Statistics of Appliance 2</h2></center>
<div class="col-lg-4">
<!-- something -->
</div>
<div class="col-lg-4">
<fieldset id="device2">
<form class="form-horizontal" action="" method="GET">
<div class="form-group">
<div class="col-lg-12">
<label class="control-label" for="focusedInput">From Date</label>
<input type="text" class="form-control" name="from_date" id="from_date" required />
</div>
</div>
<div class="form-group">
<div class="col-lg-12">
<label class="control-label" for="focusedInput">To Date</label>
<input type="text" class="form-control" name="to_date" id="to_date" required />
</div>
</div><br/>
<div class="form-group">
<center><button type="submit" id="submit" value="submit" name="submit" class="btn btn-primary">Submit</button></center>
</div>
</fieldset>
</form>
</div>
<div class="col-lg-4">
<!-- something -->
</div>
</div>
</div>
<br/>
<div class="container">
<div class="row">
<div class="col-lg-3">
<!-- something -->
</div>
<div class="col-lg-6">
<?php
if(isset($_GET['from_date'])===true && isset($_GET['to_date'])===true) {
$from = $_GET['from_date'];
$to = $_GET['to_date'];
$query = "SELECT * FROM `light_year` WHERE `lsdate` BETWEEN '$from' AND '$to'";
$result = mysql_query($query); ?>
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Start Time</th>
<th>End Time</th>
<th>Duration</th>
<th>Units (KWH)</th>
</tr>
</thead>
<tbody>
<?php while($row = mysql_fetch_assoc($result))
{ ?>
<td><?php echo $row['lsdate']; ?></td>
<td><?php echo $row['lstime']; ?></td>
<td><?php echo $row['letime']; ?></td>
<td><?php echo $row['ldhour'].':'.$row['ldmin'].':'.$row['ldsec']; ?></td>
<td><?php echo $row['units'].' '.'units'; ?></td>
</tbody>
<?php }
$query1 = "SELECT SUM(`units`),SUM(`ldurs`) FROM `light_year` WHERE `lsdate` BETWEEN '$from' AND '$to'";
$result1 = mysql_query($query1);
$row1=mysql_fetch_row($result1);
echo '<center>Total units consumed for Appliance 1: '.'<strong>'.round($row1[0],2).'</strong> units</center><br/><br/>';
}
else {
echo 'Enter valid dates to get the stats related power consumption of Appliance 1';
}
?>
</div>
<div class="col-lg-3">
<!-- something -->
</div>
</div>
</div>