On my crud website the homepage displays all published posts and just above that I’m putting the various categories as links that the posts are attributed to. so that the user can click the category link and display only the posts attributed to that particular category.
So far I have tried using a foreach to display the categories, and they do display, but it is displaying all of the categories the posts are attributed to which causes some categories to display multiple times. I think this is because multiple posts are tied to the same category. I tried placing a break like this but then it displays only one category. I wanted to see if I can get some advice on getting each category to display only once?
Also my database query contains some joins which i’m worried is limiting my options. When I click the category link though the posts do display as intended so I was hoping there is a way around this.Thank you
<?php foreach ($stmt as $row) { ?>
<h3><table><tr><th><a href="category.php?id=<?php echo $row['category_id'] ?>"><?php echo ($row['category']) ?></th></tr></table></h3>
<?php break; ?>
<?php } ?>