ThinkPHP中获得上下篇文章的函数
thinkphp中获得上下篇文章的函数,大家可以参考一下方法,稍微修改下就可以应用到其他网站上,方法一样!
//取得上下篇文章
function PrevNext($id, $name = '', $where = array(), $fields = 'id,title'){
$array = array();
$model = M($name);
$map = array();
$map = $where;
$map['id'] = array('lt',$id);
$prevL = $model->field($fields)->where($map)->order('id desc')->find(); //上篇
if(!$prevL){
$prevL['id'] = '';
$prevL['title'] = '暂无';
}
$map['id'] = array('gt',$id);
$nextL = $model->field($fields)->where($map)->order('id asc')->find(); //下篇
if(!$nextL){
$nextL['id'] = '';
$nextL['title'] = '暂无';
}
$array['prev'] = $prevL;
$array['next'] = $nextL;
return $array;
}
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号