2 回答
TA贡献1966条经验 获得超4个赞
您必须更改在 php 中输出所有表的代码,例如:
<body>
<?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){
echo '
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Emails</th>
<th>Date Created</th>
</tr>';
while($row = $result->fetch_assoc()){
echo "<tr> ";
echo "<td>" . $row["First Name"] . "</td>";
echo "<td>" . $row["Last Name"] . "</td>";
echo "<td>" . $row["Date Created"] . "</td>";
echo "</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);
?>
</body>
另一个问题你确定是$row["First Name"]不是$row["First_Name"]?
最后提示了解如何准备 stm 以防止 sql 注入
TA贡献1853条经验 获得超6个赞
根据您的代码,您尝试在下面定义实际表之前打印该表。你可以尝试这样的事情:
<?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);
$informed = mysqli_fetch_all($result, MYSQLI_ASSOC);
?>
<!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>
<body>
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Emails</th>
<th>Date Created</th>
</tr>
<?php
if ($result->num_rows>0) {
while($row = $result->fetch_assoc()){
echo "<tr><td>" . $row["First Name"] . "</td><td>" . $row["Last Name"] . "</td><td>" . $row["Emails"] . "</td><td>" . $row["Date Created"] . "</td></tr>";
}
} else {
echo "<tr><td rowspan=\"5\">0 result</td></tr>";
}
?>
</table>
</body>
<?php
// Freeing result from the memory.
mysqli_free_result($result);
mysqli_close($conn);
?>
- 2 回答
- 0 关注
- 132 浏览
添加回答
举报