Skip to content

Instantly share code, notes, and snippets.

@fernandozamoraj
Created June 24, 2018 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fernandozamoraj/18408e99da972103107ec0d74416765d to your computer and use it in GitHub Desktop.
Save fernandozamoraj/18408e99da972103107ec0d74416765d to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Books</title>
</head>
<body>
<?php
$servername = "localhost";
$username = "bpdemo";
$password = "bpdemo";
$dbname = "bpdemo";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
echo "Connection Failed....";
}
$sql = "SELECT book_id, title, author, pages FROM books";
$result = $conn->query($sql);
echo "\n <table>" .
"\n <tr> " .
"\n <th>Book Id</th>" .
"\n <th>Title</th>" .
"\n <th>Author</th>" .
"\n <th>Pages</th>" .
"\n <tr>" .
"\n ";
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "\n <tr>" .
"\n <td> " . $row['book_id'] . "</td>" .
"\n <td> " . $row['title'] . "</td>" .
"\n <td> " . $row['author'] . "</td>" .
"\n <td> " . $row['pages'] . "</td>" .
"\n </tr>";
}
}
echo "\n </table>";
$conn->close();
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment