A couple of weeks ago I started to switch from static to dynamic webpages to make life more easier. The result is looking better each day but I still got some issues that I didn't manage to fix myself.
The next thing I want to achieve is to add a link to the previous and next blog post in two divs at the bottom of each page, based on the "id".
The url for each blog post consists of an id and a title: "domain.com/id/title"
Example:
Let's say I'm reading blog post with id = 2. How can I link to the blog posts with id = 1 (previous) and 3 (next)?
<?php
(connect to database)
$id = str_replace ('-', ' ', $_GET['id']);
$sql = "SELECT * FROM `newstable` WHERE `id` = '$id'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
?>
<div class="content-title">
<?php echo $row['title'];?>
</div>
<div class="content-text">
<?php echo $row['text'];?>
</div>
<div id="previous post">
...........
(here comes the link to the previous post, I need to link to the correct url so that means I'll need to echo the id AND the title of that previous post)
</div>
<div id="next post">
...........
(here comes the link to the next post, I need to link to the correct url so that means I'll need to echo the id AND the title of that next post)
</div>