I have a function that is meant to select data from a database to be displayed in a table. The function is generating an endless loop. How may I fix that?
My code is below:
function view()
{
$db = new mysqli("localhost", "root", "", "blog");
$sql = 'SELECT * FROM news';
$result = $db->query($sql) or die($mysqli->error);
return $result->fetch_assoc();
}
?>
<table>
<tr>
<th scope="col">Title</th>
<th scope="col">Slug</th>
<th scope="col">Text</th>
</tr>
<?php while($row = view()) { ?>
<tr>
<td><?php echo $row['title']; ?></td>
<td><?php echo $row['slug']; ?></td>
<td><?php echo $row['text']; ?></td>
</tr>
<?php } ?>
</table>
Thanks.