Php 如何使用id按类别排序来保持下一页和上一页

Php 如何使用id按类别排序来保持下一页和上一页,php,mysql,Php,Mysql,我的数据库有两个表类别和文章 Category id | Category --------------------- 1 Mobiles 2 Computers -------------------- Article id | Category | title |article ------------------------------------- 1 2 title article desc 2 1 tit

我的数据库有两个表类别和文章

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>

这并不是只过滤移动设备。

您可以直接从下面的查询中获得它

$getid = $_GET['id'];
$nextdata = $db->getRow("select * from article WHERE Category=1 AND news_id > ".$getid." order by news_id ASC LIMIT 0,1");

$previousdata = $db->getRow("select * from article WHERE Category=1 AND news_id < ".$getid." order by news_id DESC LIMIT 0,1");

如果我了解您想要获得相同类别的下一篇/上一篇文章id:

下一篇文章:

$nextdata = $db->getRow("
    select * 
    from article 
    where Category = 1 and id > $current_article_id
    order by id
    limit 1
");
前一条:

$previousdata = $db->getRow("
    select * 
    from article 
    where Category = 1 and id < $current_article_id
    order by id desc
    limit 1
");

@约格什苏塔他编辑了他的问题。。以前,他将文本值作为类别来编写。。选中edit historyNIce,但当打开某些文章时,上一篇和下一篇显示相同的内容
$previousdata = $db->getRow("
    select * 
    from article 
    where Category = 1 and id < $current_article_id
    order by id desc
    limit 1
");