controller 里面
private $per_page = '45';
private $prev_link = '上一页';
private $next_link = '下一页';
function show()
{
$config = array();
$config['per_page'] = $this->per_page; //每页显示的数据数
$current_page = intval($this->input->get_post('per_page',true)); //获取当前分页页码数
if(0 == $current_page)
{
$current_page = 1;
}
$offset = ($current_page - 1 ) * $config['per_page']; //设置偏移量 限定 数据查询 起始位置(从 $offset 条开始)
$buy_info = $this->buy_model->get_buyinfolist($offset,$config['per_page'],$order='id desc');
$config['base_url'] = 'http://'.$this->config->item('base_url').'buy/show?';
$config['prev_link'] = $this->prev_link;
$config['next_link'] = $this->next_link;
$config['total_rows'] = $buy_info['total']; //获取查询数据的总记录数
$config['use_page_numbers'] = TRUE; //默认分页URL中是显示每页记录数,启用use_page_numbers后显示的是当前页码
$config['page_query_string'] = TRUE; //把 $config['enable_query_strings'] 设置为 TRUE,链接将自动地被用查询字符串(url中的参数)重写。
$this->pagination->initialize($config);
$data = array(
'buy_info' => $buy_info['res'],
'total' => $buy_info['total'],
'current_page' => $current_page,
'per_page' => $config['per_page'],
'page' => $this->pagination->create_links(),
);
$this->load->view("show_buy_view", $data);
}
model 里面
public function get_buyinfolist($offset,$num,$order='id desc')
{
$table = "auto_buyinfo";
$str_sql = "select * from {$table} where 1=1 order by {$order} limit {$offset},{$num}";
//if($condition)
//{
//$str_sql = "select * from {$table} where 1=1 and username like '%" . $condition . "%' order by {$order} limit {$offset},{$num}";
//}
return array(
'total' => $this->db->count_all('auto_buyinfo'),
'res' => $this->db->query($str_sql)->result_array(),
);
}
view 里面
在显示的地方加入<?php echo $page;?>