求助大佬们一段代码
public function get_next_page($id='',$model='news',$catid=''){$pre_where="id < {$id} and status=1 ";
$next_where="id > {$id} and status=1 ";
if(!empty($catid)){
$pre_where="id < {$id} and status=1 and catid={$catid}";
$next_where="id > {$id} and status=1 and catid={$catid}";
}
$pre = $this->db->select("id,title")->where($pre_where,"",false)->order_by("id","desc")->limit(1)->get($model)->row_array();
$next =$this->db->select("id,title")->where($next_where,"",false)->order_by("id","asc")->limit(1)->get($model)->row_array();
if($pre){
$data['pre_title']=$pre['title'];
$data['pre_url']=$model.'/show/'.$pre['id'].'.html';
}else{
$data['pre_title']='没有了';
$data['pre_url']='javascript:void(0)';
}
if($next){
$data['next_title']=$next['title'];
$data['next_url']=$model.'/show/'.$next['id'].'.html';
}else{
$data['next_title']='没有了';
$data['next_url']='javascript:void(0)';
}
return $data;
}
麻烦哪位大佬看下这个上下一页怎么调用出来,谢谢了,麻烦给个具体调用代码 什么叫做怎么调用出来?你说显示 HTML? $pager = $this->get_next_page();
echo '<a href="'.$pager['pre_url'].'">'.$pager['pre_title'].'</a> | <a href="'.$pager['next_url'].'">'.$pager['next_title'].'</a>' 框架里不是有分页吗 Hex 发表于 2018-5-14 17:32
什么叫做怎么调用出来?你说显示 HTML?
就是在内容页不知道用什么代码能把上面那代码的上下一篇调用出来,<?=$data['res']['content']?>比如这个是调用文章内容的,但是不知道怎么调用文章页上下一篇的代码 GGsimida111 发表于 2018-5-18 12:56
框架里不是有分页吗
这个不是分页,是上下一篇,想在内容页调用出来,但是不知道调用代码是什么。
<?=$data['res']['content']?>比如这个是调用文章内容的 baihangs 发表于 2018-5-21 12:34
就是在内容页不知道用什么代码能把上面那代码的上下一篇调用出来,比如这个是调用文章内容的,但是不知道 ...
上一篇,下一篇这几个字需要你手动写到视图里呀?你想自动写? Hex 发表于 2018-5-21 17:48
上一篇,下一篇这几个字需要你手动写到视图里呀?你想自动写?
上面这段代码不可以吗?我看程序写了上面我发的那段代码,但是不知道用什么代码可以调用出来 52lin 发表于 2018-5-15 14:54
$pager = $this->get_next_page();
echo ''.$pager['pre_title'].' | '.$pager['next_title'].''
不是很懂,就是我上面的代码在程序中已经写好了,就是不知道怎么在内容页调用出来上下一篇的链接 本帖最后由 52lin 于 2018-6-8 11:38 编辑
baihangs 发表于 2018-5-23 13:39
不是很懂,就是我上面的代码在程序中已经写好了,就是不知道怎么在内容页调用出来上下一篇的链接 ...
都写到这个地步了,还不会?也是醉了!!既然你说这个$data['res']['content']是文章内容,那$data['res']应该就是文章的所有数据,你可以在你的控制器里,将【上下页的数据】放到$data里面,类似于$data['res'],只不过键值换成其他的,可以是pager等等,不重复就好。
假设你的文章的数据变量为:$art_info,$art_info是一个数组,如文章内容:$art_info['content']
// 视图数据
$data = array();
// 文章内容
$data['art_info'] = $art_info;
// 根据文章id,初始化上下页数据
$data['pager'] = $this->get_next_page($art_info['id']);
// 显示视图
$this->load->view('xxxxx', $data);
那么在视图里$art_info['content']就是文章内容:<?=$art_info['content']?>
在需要显示上下页的地方这样:
<?php echo '<a href="'.$pager['pre_url'].'">'.$pager['pre_title'].'</a> | <a href="'.$pager['next_url'].'">'.$pager['next_title'].'</a>'?>
页:
[1]