php 新闻上一条下一条

public function prevnext($table,$id,$where=[]){
$ids=db($table)->field('id,title')->order('sort asc')->where($where)->column('id');
$key=array_search($id,$ids);
// 上一条
if(isset($ids[$key-1])){
$prevnext['prev']=db($table)->field('id,title,country_id')->where('id',$ids[$key-1])->find();
}else{
$prevnext['prev']=false;
}
if(isset($ids[$key+1])){
$prevnext['next']=db($table)->field('id,title,country_id')->where('id',$ids[$key+1])->find();
}else{
$prevnext['next']=false;
}
return $prevnext;
}

posted @ 2019-02-14 15:49  酷酷的城池  阅读(682)  评论(0编辑  收藏  举报