I want to display “no records found” if my query returns no results. Heres my code
<table class="table table-striped">
<tr>
<th width="75">Date</th>
<th width="200">Provider</th>
<th width="200">Author</th>
<th>Details...</th>
</tr>
<?php
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
$stmt = $dbh->prepare('SELECT ...');
$stmt->execute(array(
':p_id' => $_GET['p_id']
));
while($row = $stmt->fetch()) {
echo "<tr>";
echo "<td>".date( 'm/d/y', strtotime($row['r_date']))."</td>";
echo "<td>".$row['p_name']."</td>";
echo "<td>".$row['m_name']."</td>";
echo "<td>".$row['excerpt'].". . . <a href='review_detail.php?id=".$row['id']."'><span class='more'>[more]</span></a></td>";
echo "</tr>\n";
}
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
?>
</table>
Im thinking I got to put this before the while loop
if (is_array($fetch)) {
while() {
...
}
} else {
echo '<tr><td colspan="4" align="center">no records found!!</td></tr>';
}