我已经完成了这个 YouTube 教程:https://www.youtube.com/watch?v=1YbbUS_SxSk&t=609s
..由于某种原因,我的 mySQL 表中的数据根本没有在表中打印,尽管 HTML 表中的行数似乎是正确的。与 MySQL 的连接以及与相应表的连接似乎工作正常 - 记录只是没有打印在表中。
> <html>
<head>
<title>Delete Records</title>
</head>
<body>
<table border=1 cellpadding=1 cellspacing=1>
<tr>
<th>Image</th>
<th>Delete</th>
</tr>
<?php
//connect with mysql
$con = mysqli_connect('localhost', 'root', '');
if (!$con){
echo"Connection not established";
}
//select database
mysqli_select_db($con, 'photos');
//select query
$sql = "SELECT * FROM images";
if(!$sql){
echo"Table not selected";
}
//execute the query
$records = mysqli_query($con, $sql);
while (mysqli_fetch_array($records)){
echo "<tr>";
echo "<td>".$row['image']."</td>";
echo "<td><a href=delete.php?id=".$row['ID'].">Delete</a></td>";
echo "</tr>";
}
?>
</table>
</body>
</html>
表格最终如下所示: HTML Table
表中没有数据!
最佳答案
更改此行
while (mysqli_fetch_array($records)){
至
while ($row = mysqli_fetch_array($records)){
关于php - MySQL 记录不显示在 HTML 表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43834539/