Last active
January 24, 2023 01:14
-
-
Save macloo/7d2c4e7b9f58c6bc913768592a283212 to your computer and use it in GitHub Desktop.
A read-only page from a MySQL database - no JavaScript, no form handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php include 'database.php'; ?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name=viewport content="width=device-width, initial-scale=1"> | |
<title> Read the Shoutbox DB </title> | |
<link rel="stylesheet" href="css/main.css"> | |
</head> | |
<body> | |
<div id="container"> | |
<header> | |
<h1>My Shoutbox</h1> | |
</header> | |
<div id="shouts"> | |
<ul> | |
<!-- begin PHP code below --> | |
<?php | |
$query = "SELECT * FROM shouts ORDER BY id DESC"; | |
$shouts = mysqli_query($conn, $query); | |
// the PHP while-loop displays database query results, row by row | |
// with each row enclosed in LI tags | |
while($row = mysqli_fetch_assoc($shouts)) { | |
echo '<li>'; | |
echo $row['name'] . ': '; // put a colon and a space after name text | |
echo $row['shout']; | |
echo ' [ ' . $row['date'] . ' ]'; // put brackets around date text | |
echo '</li>'; | |
} | |
?> | |
<!-- end PHP code --> | |
<!-- everything else on this page is normal HTML, no JavaScript --> | |
</ul> | |
</div> | |
<footer> | |
<p style="text-align: center;">Read-only example from a MySQL database</p> | |
</footer> | |
</div> <!-- close container --> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Revised Jan. 23, 2023