zoukankan      html  css  js  c++  java
  • thinkphp5.0 文章详情页 上一篇 下一篇

     //    上一篇下一篇(同一个分类下,先确定该分类的pid)
        public function frontAfter()
        {
            $param=$this->param;
            $front=Db::name('news')->where(['pid'=>$param['pid']])->where('id','<',$param['id'])->field(['id','pid'])->order(['id'=>'desc'])->find();
            $after=Db::name('news')->where(['pid'=>$param['pid']])->where('id','>',$param['id'])->field(['id','pid'])->order(['id'=>'asc'])->find();
            $front=empty($front)?'没有了':$front;
            $after=empty($after)?'没有了':$after;
            $data=[$front,$after];
            return resultArray(['data'=>$data]);
        }

    测试代码php部分:

     public function fenye()
        {
            $param=$this->param;
    //        dump($param);
            $front=Db::name('news')->where(['pid'=>$param['pid']])->where('id','<',$param['id'])->order(['id'=>'desc'])->find();
            $after=Db::name('news')->where(['pid'=>$param['pid']])->where('id','>',$param['id'])->order(['id'=>'asc'])->find();
    //        echo Db::name('news')->getLastSql();
    //        dump($front);
    //        dump($after);
    
            $f_url= $front['id'];
            $a_url=$after['id'];
            $front=empty($front)?'没有了':$front;
            $after=empty($after)?'没有了':$after;
    
            $this->assign('front',$front);
            $this->assign('after',$after);
    
            $this->assign('f_url',$f_url);
            $this->assign('a_url',$a_url);
            return $this->fetch('index');
        }

    HTML部分:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>news 分页</title>
    </head>
    <body>
    <div>分页</div>
    {$front}&nbsp;&nbsp;&nbsp;--{$after}<br>
    <a href="{$f_url}">上一页</a> &nbsp;&nbsp;&nbsp; <a href="{$a_url}">下一页</a>
    </body>
    </html>
  • 相关阅读:
    图论
    数学
    P2222 外婆婆~
    P2083 找人
    P1215 [USACO1.4]母亲的牛奶 Mother's Milk
    New Rap
    P2298 Mzc和男家丁的游戏
    P2040 打开所有的灯
    P1135 奇怪的电梯
    UVA10474 Where is the Marble?
  • 原文地址:https://www.cnblogs.com/lxwphp/p/8243547.html
Copyright © 2011-2022 走看看