<?php
$sql = "SELECT * FROM posts ORDER BY created_at DESC";
$statement = $connection->prepare($sql);
$statement->execute();
$statement->setFetchMode(PDO::FETCH_ASSOC);
$posts = $statement->fetchAll();
?>
<?php foreach ($posts as $post) { ?>
<div class="blog-post">
<a href="single-post.php"><h2 class="blog-post-title"> <?php echo($post['title']) ?></h2></a>
<p class="blog-post-meta"><?php echo($post['created_at']) ?> by <a href="#"> <?php echo($post['author']) ?></a></p>
<p><?php echo($post['body']) ?></p>
</div>
<?php } ?>
In this example, I loop though every single "post" from my blog's database and as you can see, the posts title is also a link that leads to its specific post's separate page. In that single-page.php file, instead of looping thought each row or rather "post" from my database I want it to generate an exact post I clicked on.