My own personal preference when outputting things like this is to put the portion where data is actually retrieved in a separate file and then use the alternate PHP structure syntax. While this probably isn't everyone's preferred coding style, in my opinion it makes it easier to structure HTML so that its readable among the PHP. From what I have seen, this appears to be relatively common in templates.
Just a quick once-over your file to show you what I mean:
<?php
require 'DB.php'
try {
$stmt = $conn->query('SELECT * FROM equipment');
}
catch(PDOException $e){
echo'ERROR: ' . $e->getMessage();
die();
}
?>
<table class='tableTwo'>
<tr>
<th>Equipment Type</th>
<th>Unit Number</th>
<th>Last Updated</th>
<th>CurrentHours</th>
<th>Scheduled PM</th>
</tr>
<?php while($row = $stmt->fetch()): ?>
<tr>
<td><?php echo htmlspecialchars($row['equipType']); ?></td>
<td><?php echo htmlspecialchars($row['unitNumber']); ?></td>
<td><?php echo htmlspecialchars($row['lastUpdate']); ?></td>
<?php if ($row['nextPM'] - $row['currentHours'] > 100): ?>
<td class='good'><?php echo htmlspecialchars($row['currentHours']); ?></td>
<td class='good'><?php echo htmlspecialchars($row['nextPM']); ?></td>
<?php elseif ($row['nextPM'] - $row['currentHours'] < 100 && $row['nextPM'] - $row['currentHours'] > 50): ?>
<td class='soon'><?php echo htmlspecialchars($row['currentHours']); ?></td>
<td class='soon'><?php echo htmlspecialchars($row['nextPM']); ?></td>
<?php else: ?>
<td class='bad'><?php echo htmlspecialchars($row['currentHours']); ?></td>
<td class='bad'><?php echo htmlspecialchars($row['nextPM']); ?></td>
<?php endif; ?>
</tr>
<?php endwhile; ?>
</table>
Again, if I were doing this I would separate that top half into another file and have that file include your "template" which would output the actual HTML. You could also use a template engine like Savant3 to make the separation a little cleaner and the templating better.
Demonstration with savant3:
Your main file (index.php perhaps?):
<?php
require 'DB.php'
require_once 'Savant3.php'
$tpl = new Savant3();
try {
$stmt = $conn->query('SELECT * FROM equipment');
$tpl->data = $stmt;
}
catch(PDOException $e){
echo'ERROR: ' . $e->getMessage();
die();
}
$tpl->display('table.tpl.php');
?>
Then in your template file (table.tpl.php in this example):
<table class='tableTwo'>
<tr>
<th>Equipment Type</th>
<th>Unit Number</th>
<th>Last Updated</th>
<th>CurrentHours</th>
<th>Scheduled PM</th>
</tr>
<?php foreach($this->data as $row): ?>
<?php $class = "bad";
if ($row['nextPM'] - $row['currentHours'] > 100) {
$class = "good";
}
elseif ($row['nextPM'] - $row['currentHours'] < 100 && $row['nextPM'] - $row['currentHours'] > 50) {
$class = "soon";
}
?>
<tr>
<td><?php echo htmlspecialchars($row['equipType']); ?></td>
<td><?php echo htmlspecialchars($row['unitNumber']); ?></td>
<td><?php echo htmlspecialchars($row['lastUpdate']); ?></td>
<td class='<?php echo $class; ?>'><?php echo htmlspecialchars($row['currentHours']); ?></td>
<td class='<?php echo $class; ?>'><?php echo htmlspecialchars($row['nextPM']); ?></td>
</tr>
<?php endforeach; ?>
</table>
Note that I changed the while into a foreach because I personally don't like doing an assignment and comparison in the same statement. You can foreach over a PDOStatement (as far as I know) just as well as you can fetch from it.
EDIT: Also, you don't necessarily need to prepare the statment with the PDOs if there are no arguments. Of course, that's all up to preference again. If you have arguments, though, definitely use the prepared statements.