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>
  • 相关阅读:
    xpath语法速查
    负载均衡设计
    Nginx负载均衡配置实例详解
    实现基于DNS的负载均衡
    建立双线服务器(双线游戏服务器)
    python学习
    python多线程概念
    python 多线程就这么简单(续)
    打包一沓开源的 C/C++ 包管理工具送给你!
    讲解开源项目:功能强大的 JS 文件上传库
  • 原文地址:https://www.cnblogs.com/lxwphp/p/8243547.html
Copyright © 2011-2022 走看看