我正在尝试将 mySQL 数据库打印到 html 表中。我看过很多关于如何做到这一点的教程,但不确定我如何在我的 php 代码中引用 html 表。信息打印得很好并连接到数据库,但由于某种原因它没有以表格格式输出。
<?php
$conn = mysqli_connect('localhost', 'Admin', 'admin1', 'info');
if (!$conn) {
echo "Connection failed:" . mysqli_connect_error();
}
//Writing query for database.
$sql = "SELECT `First Name`,`Last Name`,Emails,`Date Created` FROM clientinfo ORDER BY `Date Created`";
//Querying and getting results
$result = mysqli_query($conn, $sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["First Name"] . "</td></tr>" . $row["Last Name"] . "</td></tr>"
. $row["Emails"] . "</td></tr>" . $row["Date Created"] . "</td></tr>";
}
echo "</table>";
} else {
echo "0 result";
}
//Fetch resulting rows as an array
$informed = mysqli_fetch_all($result, MYSQLI_ASSOC);
// Freeing result from the memory.
mysqli_free_result($result);
mysqli_close($conn);
?>
<!DOCTYPE html>
<html>
<head>
<div class="Contained">
<div class="row">
<?php foreach ($informed as $inform) { ?>
<div class="col s6 medium-3">
<div class="card z-depth-0">
<div class="card-content center">
<h6><?php echo htmlspecialchars($inform['First Name']); ?></h6>
<div><?php echo htmlspecialchars($inform['Last Name']); ?></div>
</div>
<div class="card-action right-align">
<a class="brand-text" href="#">More Info
</div>
</div>
</div>
<?php } ?>
</div>
</div>
<title> Email and Name List </title>
</head>
慕标5832272
墨色风雨