There are multiple issues:
- Table rows had not been closed (
</tr>
)
- Usage of
mysql_*
functions is deprecated in PHP 5 and removed in PHP 7; if you're writing new code, you should not be using mysql_*
functions. Instead, use mysqli_*
functions or the PDO library.
- There were multiple for-loops to get records, but it would create new tables each iteration.
- The table attribute "cellspacing" was misspelled.
- The results object where they are stored can either be a resource or false.
Given these, I've made the following changes that will fix the above problems:
<?php
// I've commented out the connect.php file inclusion to highlight the change to how
// you'd connect to the MySQL database using mysqli_* instead of mysql_*. I'm guessing
// as to the contents of connect.php, but this should still highlight what needs to be
// done
// include('connect.php');
$db_connection = mysqli_connect('host', 'user', 'pass', 'database_name');
$employee_results = mysqli_query($db_connection, "SELECT id,username FROM user ORDER BY id");
?>
<html>
<body>
<table width="600" border="1" cellpadding="1" cellspacing="1">
<tr>
<th class="active">ID</th>
<th class="active">Name</th>
</tr>
<?php if ($employee_results === false): ?>
<tr>
<td colspan="2">No users</td>
</tr>
<?php else: ?>
<?php while ($employee = mysqli_fetch_assoc($employee_results)): ?>
<tr>
<td><?= $employee['id'] ?></td>
<td><?= $employee['username'] ?></td>
</tr>
<?php endwhile ?>
<?php endif ?>
</table>
</body>
</html>