Last active
March 14, 2023 18:39
-
-
Save pchatterjee/1eecfd8909facd3f837f720d703ba448 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <!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) { | |
| if ($key == "img") { | |
| echo '<td><img alt="' . $val . '" width="90px" src="./images/' . $val . '" /></td>'; | |
| } elseif ($key == "email") { | |
| echo '<td><a href="mailto:' . $val . '">' . $val . "</a></td>"; | |
| } elseif ($key == "favsite") { | |
| echo '<td><a target= "_blank" href="' . $val . '">' . $val . "</a></td>"; | |
| } else { | |
| 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