PHP / PDO echo data from database into a table

Ok so I have figured it out

<?php
$getUser = $db->prepare("SELECT * FROM users");
$getUser->execute();
$users = $getUsers->fetchAll();

<table>
    <tr>
      <th>Username</th>
      <th>Password</th>
    </tr>
<?php foreach ($users as $user) { ?>
<tr>
   <td><?php echo $users['username'] ?></td>
   <td><?php echo $users['password'] ?></td>
</tr>
<?php } ?>
</table>

It now echo’s every username and password inside the table. even if I add new ones in the database I just hit refresh and they are added.

Sorry for writing my question in a confusing way.

Leave a Comment