我的数据库有 2 个表 "category" 和 "article" ,
Category
id | Category
---------------------
1 Mobiles
2 Computers
--------------------
Article
id | Category | title |article
-------------------------------------
1 2 title article desc
2 1 title article desc
3 1 title article desc
4 1 title article desc
5 2 title article desc
--------------------------------------
我为文章页面生成的 url 就是这种格式。
URL/ID/TITLE
我想在当前文章页面中显示下一篇和上一篇文章的标题。
所以我使用下面的代码来显示下一个和上一个标题的链接。
上一篇文章
$getid = $_GET['id'];
$previous = $getid - 1;
$previousdata = $db->getRow("select * from article WHERE news_id='$previous'");
下一篇
$getid = $_GET['id'];
$next = $getid + 1;
$nextdata = $db->getRow("select * from article WHERE news_id='$next'");
和 php 代码之类的
<a href="http://www.domain.com/article-<?php echo ($previousdata['news_id']); ?>/<?php echo friendlyURL($previousdata['title']); ?>"> <?php echo friendlyURL($previousdata['title']); ?></a>
这很好用,它使用 id 显示下一个和上一个链接中的手机和计算机帖子,
if i post 2 articles in mobiles category the generated id was 12 and 13 for example, and next if i post an article in computer category the generated id was 14. when the user reading mobile article of id 13 ,at bottom it shows previous article title with id 12 and next article title with id of 14 . Obviously the previous article is mobile and next is computers categories.
But i would like to show only the next and previous pagination with "mobiles" category only,
So i try to assign the category
$getid = $_GET['id'];
$next = $getid + 1;
$nextdata = $db->getRow("select * from article WHERE Category=1 AND id='$next'");
This doesn't filter only mobile ..