HS Banner
Back
Populate HTML Table on Page Load.

Author: Admin 06/17/2022
Language: PHP
Views: 455
Tags: html php table foreach


Description:

Here's a simple way to populate an HTML table on page load using PHP.

Article:

<?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>

 



Back
Comments
Add Comment
There are no comments yet.