我已经通过这个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
表中没有数据!
答案 0 :(得分:2)
更改此行
while (mysqli_fetch_array($records)){
要
while ($row = mysqli_fetch_array($records)){
答案 1 :(得分:0)
简单错误
while ($row = mysqli_fetch_array($records))
这应该用于允许自由流动的代码