Skip to content

Instantly share code, notes, and snippets.

@pchatterjee
Last active March 14, 2023 17:55
Show Gist options
  • Select an option

  • Save pchatterjee/5d3831def8ee73b13abc32971af2747b to your computer and use it in GitHub Desktop.

Select an option

Save pchatterjee/5d3831def8ee73b13abc32971af2747b to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset='UTF-8'>
<title>CSV to HTML5 Table Example </title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous" />
<style>
body {
margin: 20px auto;
font-family: Georgia, serif;
font-weight: 500;
font-size: 16px;
margin-left: 12px;
}
h3 {
color: darkblue;
}
th {
font-family: tahoma, helvetica, arial, sans-serif;
font-size: 0.8em;
color: crimson;
}
</style>
</title>
</head>
<body>
<h3>Survey Results:</h3>
<?php
$conn = new mysqli("localhost", "root", "", "survey-db");
echo '<table class="table table-striped table-bordered" style="width:600px">';
$sql_cols = "SHOW COLUMNS FROM results";
$sql_recs = "SELECT * FROM results";
$cols = mysqli_query($conn, $sql_cols);
$recs = mysqli_query($conn, $sql_recs);
echo "<p><strong>" . mysqli_num_rows($recs) . " records found in the database.</strong></p>";
echo "<tr>";
while ($row = mysqli_fetch_array($cols)) {
echo "<th>" . $row["Field"] . "</th>";
}
echo "</tr>";
while ($row = mysqli_fetch_assoc($recs)) {
echo "<tr>";
foreach ($row as $key => $val) {
switch ($key) {
case "img":
echo '<td><img alt="' . $val . '" width="90px" src="./images/' . $val . '" /></td>';
break;
case "email":
echo '<td><a href="mailto:' . $val . '">' . $val . "</a></td>";
break;
case "favsite":
echo '<td><a target= "_blank" href="' . $val . '">' . $val . "</a></td>";
break;
default:
echo "<td>" . $val . "</td>";
}
}
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment