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}
To find an article, you should use find $nex = Db('shcontent')->where('id','<',$id)->order('id desc')-> limit('1')->find();
Solved, just use ["id"=>$val["id"]+1] or ["id"=>$val["id"]-1]