forked from kokonior/PHP-Projects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddSensorData.php
66 lines (58 loc) · 1.75 KB
/
addSensorData.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
<?php
require("koneksi.php"); // memanggil file koneksi.php untuk koneksi ke database
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="5">
</head>
<body>
<style>
#wntable {
border-collapse: collapse;
width: 50%;
}
#wntable td, #wntable th {
border: 1px solid #ddd;
padding: 8px;
}
#wntable tr:nth-child(even){background-color: #f2f2f2;}
#wntable tr:hover {background-color: #ddd;}
#wntable th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
background-color: #00A8A9;
color: white;
}
</style>
<div id="cards" class="cards" align="center">
<h1> Data Sensor</h1>
<table id="wntable">
<tr>
<th>No</th>
<th>Data</th>
<th>Waktu</th>
</tr>
<?php
$sql = mysqli_query($koneksi, "SELECT * FROM pemograman3 ORDER BY id DESC");
if (mysqli_num_rows($sql) == 0) {
echo '<tr><td colspan="14">Data Tidak Ada.</td></tr>'; // jika tidak ada entri di database maka tampilkan 'Data Tidak Ada.'
}else { // jika terdapat entri maka tampilkan datanya
$no = 1; // mewakili data dari nomor 1
while($row = mysqli_fetch_assoc($sql)){ // fetch query yang sesuai ke dalam array
echo '
<tr>
<td>'.$no.'</td>
<td>'.$row['dht_temp'].'</td>
<td>'.$row['db_time'].'</td>
</tr>
';
$no++; // mewakili data kedua dan seterusnya
}
}
?>
</table>
</div>
</body>
</html>