Reputation: 3438
I've worked my way through this Youtube tutorial: https://www.youtube.com/watch?v=1YbbUS_SxSk&t=609s
..and for some reason, my data from my mySQL table is not printing at all within the table, though there appears to be the correct number of rows within the HTML table. Connection to MySQL and connection with the appropriate table seems to be working fine - the records are just not printing in the table.
> <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>
This is what the table ends up looking like: HTML Table
No data in the table!
Upvotes: 0
Views: 33
Reputation: 1
Simple error
while ($row = mysqli_fetch_array($records))
This should be used to allow free flowing code
Upvotes: 0
Reputation: 670
Change this line
while (mysqli_fetch_array($records)){
To
while ($row = mysqli_fetch_array($records)){
Upvotes: 2