better dbview

This commit is contained in:
Patrick McGuire
2021-10-14 09:33:42 -04:00
parent f843e282ec
commit 7c8620ff5f
+114 -44
View File
@@ -1,45 +1,115 @@
<html>
<head>
<title>'birds' database 'detections' table</title>
</head>
<body>
<?php
$dbhost = 'localhost';
$dbuser = 'birder';
$dbpass = 'databasepassword';
$dbname = 'birds';
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if($mysqli->connect_errno ) {
printf("Connect failed: %s<br />", $mysqli->connect_error);
exit();
}
printf('Connected successfully.<br />');
$sql = 'SELECT * FROM detections';
$result = $mysqli->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
printf("Date: %s || Time: %s || Sci_Name: %s || Com_Name: %s || Confidence: %s || Lat: %s || Lon: %s || Cutoff: %s || Week: %s || Sens: %s || Overlap: %s <br />",
$row["Date"],
$row["Time"],
$row["Sci_Name"],
$row["Com_Name"],
$row["Confidence"],
$row["Lat"],
$row["Lon"],
$row["Cutoff"],
$row["Week"],
$row["Sens"],
$row["Overlap"]);
}
} else {
printf('No record found.<br />');
}
mysqli_free_result($result);
$mysqli->close();
?>
</body>
<?php
// Username is root
$user = 'birder';
$password = 'databasepassword';
// Database name is gfg
$database = 'birds';
// Server is localhost with
// port number 3308
$servername='localhost';
$mysqli = new mysqli($servername, $user, $password, $database);
// Checking for connections
if ($mysqli->connect_error) {
die('Connect Error (' .
$mysqli->connect_errno . ') '.
$mysqli->connect_error);
}
// SQL query to select data from database
$sql = "SELECT * FROM detections";
$result = $mysqli->query($sql);
$mysqli->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Birds Database, Detections Table</title>
<!-- CSS FOR STYLING THE PAGE -->
<style>
table {
margin: 0 auto;
font-size: large;
border: 1px solid black;
}
h1 {
text-align: center;
color: #006600;
font-size: xx-large;
font-family: 'Gill Sans', 'Gill Sans MT',
' Calibri', 'Trebuchet MS', 'sans-serif';
}
td {
background-color: #E4F5D4;
border: 1px solid black;
}
th,
td {
font-weight: bold;
border: 1px solid black;
padding: 10px;
text-align: center;
}
td {
font-weight: lighter;
}
</style>
</head>
<body>
<section>
<h1>BirdsDB Detections Table</h1>
<!-- TABLE CONSTRUCTION-->
<table>
<tr>
<th>Date</th>
<th>Time</th>
<th>Sci_Name</th>
<th>Com_Name</th>
<th>Confidence</th>
<th>Lat</th>
<th>Lon</th>
<th>Cutoff</th>
<th>Week</th>
<th>Sens</th>
<th>Overlap</th>
</tr>
<!-- PHP CODE TO FETCH DATA FROM ROWS-->
<?php // LOOP TILL END OF DATA
while($rows=$result->fetch_assoc())
{
?>
<tr>
<!--FETCHING DATA FROM EACH
ROW OF EVERY COLUMN-->
<td><?php echo $rows['Date'];?></td>
<td><?php echo $rows['Time'];?></td>
<td><?php echo $rows['Sci_Name'];?></td>
<td><?php echo $rows['Com_Name'];?></td>
<td><?php echo $rows['Confidence'];?></td>
<td><?php echo $rows['Lat'];?></td>
<td><?php echo $rows['Lon'];?></td>
<td><?php echo $rows['Cutoff'];?></td>
<td><?php echo $rows['Week'];?></td>
<td><?php echo $rows['Sens'];?></td>
<td><?php echo $rows['Overlap'];?></td>
</tr>
<?php
}
?>
</table>
</section>
</body>
</html>