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>
  • 相关阅读:
    十七 SpringCloud Alibaba入门简介
    十六、Spring Cloud Sleuth 分布式请求链路追踪
    Linux下安装mongo
    MongoDB零基础入门到高级进阶-尚学堂
    十五、Spring Cloud Stream 消息驱动
    十四、SpringCloud Bus 消息总线
    十二、Gateway新一代网关
    十一、Zuul路由网关
    十、Hystrix熔断器(三)服务熔断
    十、Hystrix 断路器(二)服务降级
  • 原文地址:https://www.cnblogs.com/lxwphp/p/8243547.html
Copyright © 2011-2022 走看看