I have two tables “categories” and “posts”, I’m trying to create a category.php page that displays the different categories with post titles as links to the original posts. I’ve tried different variations of loops but can’t seem to get it right. I’m hoping someone could point me in the right direction.
$query = "SELECT post_id, title, body, category_id, posted
FROM posts
INNER JOIN categories ON categories.category_id = posts.category_id";
$result = mysqli_query($dbc, $query)
or die('Error querying database.');
while ($row = mysqli_fetch_array($result)){
<a href='index.php?id=<?php echo $post['post_id']; ?>' ><?php echo $post['title']; ?></a></h2>
<p>
Posted on <?php echo date('d-m-y h:i:s',strtotime($post['date_posted'])); ?>
In <a href='category.php?id=<?php echo $post['category_id']; ?>' ><?php echo $post['name']; ?></a>
</p>
echo "<hr />";
}
Thank you for any input