|
$news=$tnews['news'];
//print_r($news); exit();
//分页信息设置
$config['page_query_string']=TRUE;
$config['base_url']=base_url('index/newslist?tid='.$tid);
$config['total_rows']=count($news);
$config['per_page']=7;
$config['last_link'] = '尾页';
$config['first_link'] = '首页';
$config['next_link'] = '下一页';
$config['prev_link'] = '上一页';
$config['num_links'] = 4;
$config['display_pages'] = TRUE;
$config['use_page_numbers'] = TRUE;
$this->pagination->initialize($config);//分页初始化
$offset= (int)($this->input->get('per_page'));
//print_r($offset);exit();
if($news)
{
$data['news']=array_slice($news,$offset,$config['per_page']);
$data['totalpage']=floor(($config['total_rows']+$config['per_page']-1)/$config['per_page']);
$data['totalnum']=count($data['news']);
$this->load->view('newslist_v',$data);
}
else
{
$data['news']='';
$data['totalnum']=0;
$this->load->view('newslist_v',$data);
}
如果不强制转换$offset为int型变会报错 Message: array_slice() expects parameter 2 to be long, string given
但是转换后便会出现每页的新闻重复。
该如何解决?
|
|