Skip to content

Instantly share code, notes, and snippets.

@borch84
Created November 16, 2015 19:36
Show Gist options
  • Save borch84/b479008f0fb754c8e1e6 to your computer and use it in GitHub Desktop.
Save borch84/b479008f0fb754c8e1e6 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Customers</title>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
font-family: sans-serif;
padding: 5px;
}
table tr:nth-child(even) td {
background-color: #95c7ea;
}
</style>
</head>
<body>
<?php
$servername = "<%= node['awesome_customers']['database']['host'] %>";
$username = "<%= node['awesome_customers']['database']['app']['username'] %>";
$password = "<%= @database_password %>";
$dbname = "<%= node['awesome_customers']['database']['dbname'] %>";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Perform SQL query
$sql = "SELECT * FROM customers";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
echo "<table>\n";
// Output data of each row
while($row = $result->fetch_assoc()) {
echo "\t<tr>\n";
foreach ($row as $col_value) {
print "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>";
} else {
echo "0 results";
}
// Close connection
$conn->close();
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment