-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.php
executable file
·53 lines (48 loc) · 1.37 KB
/
index.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
<?php
include "header.php";
include "meterParams.php";
?>
<div id="content">
<div class="table">
<?php
// connect to db
include "dbConnect.php"; // $link = mysqli_connect("hostname", "utility_mon", "password", "UtilityMon"); ...
// print a list of customer id's
$result = $link->query("SELECT mId, mType, avg(mConsumed) FROM UtilityMeter GROUP BY mId");
if($result) {
echo $result->num_rows." Meters found";
} else {
die("Query Failed: ".$link->error);
}
echo "<div class='row'>";
echo "<div class='cell'>Customer</div>";
echo "<div class='cell'>Meter Type</div>";
echo "<div class='cell'>Avg Use</div>";
echo "</div>";
while($row=$result->fetch_array(MYSQLI_ASSOC)) {
$mId = $row['mId'];
$mType = $row['mType'];
$mAvg = sprintf("%.2f", $row['avg(mConsumed)']);
// determine type
$mTypeStr = "";
if(in_array($mType, $electricMeterTypes)) {
$mTypeStr = "Electric";
$mTypeUnit = "Watts";
} elseif(in_array($mType, $gasMeterTypes)) {
$mTypeStr = "Gas";
$mTypeUnit = "Cubic Feet/Sec";
} elseif(in_array($mType, $waterMeterTypes)) {
$mTypeStr = "Water";
$mTypeUnit = "Cubic Feet/Sec";
}
echo "<div class='row'>";
echo "<div class='cell'><a href='meter.php/?id=$mId'>$mId</a></div>";
echo "<div class='cell'>$mTypeStr</div>";
echo "<div class='cell'>$mAvg $mTypeUnit</div>";
echo "</div>";
}
?>
</div>
</div>
</body>
</html>