search

Home  >  Q&A  >  body text

thinkphp5 implements the next article and the previous article. Clicking cannot jump to the page number. How to solve it?

Controller code:

//Next article

$after = Db('shcontent')->where('id','>' ,$id)->order('id asc')->limit('1')->select();

//Previous article

$nex = Db('shcontent')->where('id','<',$id)->order('id desc')->limit('1')->select();

View code:

<!--Next article-->

{if condition="$after"}

{foreach $after as $va}

<a style="float: right;" href="{:url('index/index/shenghuo_content',["id"=>$val["id "]])}">Next article: {$va.title}</a>

{/foreach}

{else/}

< ;a style="float: right;" href="#">Next article: None</a>

{/if}

<!--Previous One article-->

{if condition="$nex"}

{foreach $nex as $va}

<a style="float: right ;" href="{:url('index/index/shenghuo_content',["id"=>$val["id"]])}">Previous article: {$va.title}</ a>

{/foreach}

{else/}

<a style="float: right;" href="#">Previous article: No more</a>

{/if}

<a style="float: right;" href="#">Previous article: No more</ a>

{/if}


雪梦晨、曦雪梦晨、曦2318 days ago1395

reply all(2)I'll reply

  • Summer

    Summer2018-09-20 15:19:10

    To find an article, you should use find $nex = Db('shcontent')->where('id','<',$id)->order('id desc')-> limit('1')->find();

    reply
    0
  • 雪梦晨、曦

    Thanks for the answer

    雪梦晨、曦 · 2018-09-20 15:56:53
  • 雪梦晨、曦

    雪梦晨、曦2018-09-20 15:07:50

    Solved, just use ["id"=>$val["id"]+1] or ["id"=>$val["id"]-1]

    reply
    0
  • Cancelreply