首页 > 技术文章 > php 新闻上一条下一条

chengfengchi 2019-02-14 15:49 原文

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;
}

推荐阅读