Author: Admin 06/17/2022
Language:
PHP
Tags: html php table foreach
Here's a simple way to populate an HTML table on page load using PHP.
<?php
//Load names and addresses from SQL
require "userslib.php";
$app = new userslib();
$UsersResult = $app->LoadUsers('SELECT * FROM users order by name');
?>
<table>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Address</th>
</tr>
</thead>
<tbody>
<?php foreach ($UsersResult as $value) { ?>
<tr>
<th>
<?=$value['name']?>
</th>
<th>
<?=$value['address']?>
</th>
</tr>
<?php } ?>
</tbody>
</table>