【发布时间】:2014-08-12 09:34:31
【问题描述】:
几周前,我开始从静态网页切换到动态网页,以使生活更轻松。结果每天看起来都更好,但我仍然遇到一些我自己无法解决的问题。
接下来我要实现的是在每个页面底部的两个 div 中添加上一篇和下一篇博文的链接,基于“id”。
每篇博文的 url 由一个 id 和一个标题组成:“domain.com/id/title”
示例:
假设我正在阅读 id = 2 的博文。如何链接到 id = 1(上一个)和 3(下一个)的博文?
<?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>
【问题讨论】:
-
究竟是什么问题,获取正确的 id 或生成链接?
-
你的id的数据类型是什么??
-
@jeroen 获取正确的 ID 和标题是问题所在。
标签: php post hyperlink echo blogs