MySQLi在表中显示结果



我试图使用MySQLi显示PHPMyAdmin生成的数据到表中,我似乎无法弄清楚。

<tr>
<th scope="col">Link</th>
<th scope="col">Category</th>
</tr>
<?php
//Connection Information
$connection = mysqli_connect('localhost','root',''); //establish connection to db
$selected = mysqli_select_db($connection, 'sample'); //select db

//SQLi Statements
$viewQuery = "select * from link JOIN categories";
$execute = mysqli_query($connection,$viewQuery);
if($execute)
{
while($row = mysqli_fetch_array($execute))
{
$link = $row['link'];
$category = $row['category'];
}
}
?>
<tr>
<td><?php echo $link; ?></td>
<td><?php echo $category; ?></td>
</tr>
</table>

我错过了什么吗?我是新MySQLi

您正在覆盖变量而不使用它。我猜应该是这样的

while($row = mysqli_fetch_array($execute)){
$link = $row['link'];
$category = $row['category'];
?>
<tr>
<td><?php echo $link; ?></td>
<td><?php echo $category; ?></td>
</tr>
<?php
}