How to Display Database Table Rows as HTML
In PHP, retrieving data from a database is a common task. However, when you wish to display multiple table rows, you might face challenges.
To resolve this issue, you can use the following steps:
.
Once all rows have been echoed, close the HTML table. Here is an example code that demonstrates these steps: <code class="php">$sql = "SELECT * FROM MY_TABLE"; $result = mysqli_query($conn, $sql); echo "<table border='1'>"; while ($row = mysqli_fetch_assoc($result)) { echo "<tr>"; foreach ($row as $field => $value) { echo "<td>" . htmlspecialchars($value) . "</td>"; } echo "</tr>"; } echo "</table>";</code> This code will generate an HTML table with all the rows from the database table. The above is the detailed content of How to Display Database Table Rows as HTML in PHP?. For more information, please follow other related articles on the PHP Chinese website! Statement: The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn Previous article:How to Securely Store IP Addresses in MySQL Databases with PHP?Next article:How to Securely Store IP Addresses in MySQL Databases with PHP? Related articlesSee more |