Home  >  Article  >  Backend Development  >  TP3.2 realizes switching between previous and next chapters

TP3.2 realizes switching between previous and next chapters

一个新手
一个新手Original
2017-09-13 09:19:111523browse

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(&#39;get.id&#39;);             
            //上一篇
        $shang = M(&#39;article&#39;)->where("a_id <$idds and a_keyword=489")->order(&#39;a_id desc&#39;)->limit(&#39;1&#39;)->find();//查数据
            if($shang){//              判断如果执行成功往前面扔
        $this->assign(&#39;shang&#39;,$shang);

       }       
       else{//         否则让他的标题等于暂无吧
            $shang[&#39;a_title&#39;] = "暂无";            
            $this->assign(&#39;shang&#39;,$shang);
        }        
//      下一篇
//同上
             $xia = M(&#39;article&#39;)->where("a_id >$idds and a_keyword=489")->order(&#39;a_id asc&#39;)->limit(&#39;1&#39;)->find();         
         if($xia){        
             $this->assign(&#39;xia&#39;,$xia);

       }       
       else{            
           $xia[&#39;a_title&#39;] = "暂无";            
           $this->assign(&#39;xia&#39;,$xia);
        }        
        
           $this->display(&#39;jiu:public/7-6newsview&#39;);
     }

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn