thinkphp5.0 文章详情页 上一篇 下一篇
2018-01-08 16:54
225 查看
// 上一篇下一篇(同一个分类下,先确定该分类的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} --{$after}<br> <a href="{$f_url}">上一页</a> <a href="{$a_url}">下一页</a> </body> </html>
相关文章推荐
- php ThinkPHP文章上一篇、下一篇解决方案
- ThinkPHP实现文章上一篇和下一篇
- Thinkphp 3.2中文章详情页的上一篇 下一篇文章功能
- php ThinkPHP文章上一篇、下一篇解决方案
- DNS欺骗(挺有意思的一篇文章)
- 一篇感人的文章——母爱情深
- 转一篇正则表达式的文章,以后可能用到
- 一篇关于spring ioc 依赖注入3种方式的文章引用
- 介绍Java Socket编程的一篇不错的文章
- 和网友“凡人.net”的一篇讨论文章,权当灌水了。。。
- 靠,第一次来,花了半个多小时写一篇文章,一提交居然出错
- 一篇文章带你看懂Cloudflare信息泄露事件
- 介绍一篇关于session的好文章,写的很详细(jsp-servlet 技术)
- 介绍一篇很不错的Objective-C的文章
- 统计一篇文章中每个单词出现的次数
- 一篇文章让你看清楚运维的发展方向
- 一篇叫“知识的错误”的文章
- [thinkPHP5项目实战_28]前台文章"相关文章"的功能完善
- 一篇文章学会C#的正则表达式
- 介绍一篇关于session的好文章,写的很详细