query($sql)) { echo 'The categories could not be displayed, please try again later.'; } else { if($result->num_rows == 0) { echo 'No categories defined yet.'; } else { //prepare the table echo '
| Category | Last topic |
|---|---|
';
echo '' . htmlentities($row['catName'], ENT_QUOTES | ENT_HTML5, 'UTF-8') . '' . htmlentities($row['catDescr'], ENT_QUOTES | ENT_HTML5, 'UTF-8'); echo ' | ';
echo ''; //fetch last topic for each cat $topicsql = "SELECT topicNo, topicSubject, topicDate, topicCat FROM topics WHERE topicCat = ? ORDER BY topicDate DESC LIMIT 1"; $stmt = $conn->prepare($topicsql); $stmt->bind_param('i', $row['catNo']); $stmt->execute(); if(!$topicsresult = $stmt->get_result()) { echo 'Last topic could not be displayed.'; } else { if($topicsresult->num_rows == 0) { echo 'no topics'; } else { while($topicrow = $topicsresult->fetch_assoc()) echo '' . htmlentities($topicrow['topicSubject'], ENT_QUOTES | ENT_HTML5, 'UTF-8') . ' on ' . htmlentities(date('d-m-Y', strtotime($topicrow['topicDate'])), ENT_QUOTES | ENT_HTML5, 'UTF-8'); } } echo ' | '; echo '