Home > Article > Backend Development > TP3.2 realizes switching between previous and next chapters
To implement the previous article and the next article, a primary key value needs to be passed. Let’s take news as an example. The first is the news list. When I click on the list, I will enter the content page, so when I click on the news list:
Front-end page:
<span>{$v.a_content}</span><a href="{$v.a_writer}?id={$v.a_id}">阅读详细</a></p></p></section>
In this way, you can get the primary key; then enter the content page
The content page has the previous article and Next article;
Controller:
<? //新闻内 public function index04(){ $this->ff(); $idds = I('get.id'); //上一篇 $shang = M('article')->where("a_id <$idds and a_keyword=489")->order('a_id desc')->limit('1')->find();//查数据 if($shang){// 判断如果执行成功往前面扔 $this->assign('shang',$shang); } else{// 否则让他的标题等于暂无吧 $shang['a_title'] = "暂无"; $this->assign('shang',$shang); } // 下一篇 //同上 $xia = M('article')->where("a_id >$idds and a_keyword=489")->order('a_id asc')->limit('1')->find(); if($xia){ $this->assign('xia',$xia); } else{ $xia['a_title'] = "暂无"; $this->assign('xia',$xia); } $this->display('jiu:public/7-6newsview'); }
Front end:
##
<span class="prev">上一篇:<A href="{$shang.a_writer}?id={$shang.a_id}">{$shang.a_title}</A></span> <span class="next">下一篇:<A href="{$xia.a_writer}?id={$xia.a_id}">{$xia.a_title}</A></span>
The above is the detailed content of TP3.2 realizes switching between previous and next chapters. For more information, please follow other related articles on the PHP Chinese website!