我在codeigniter中搜索分页时遇到问题
选择其他页面链接
选择其他链接时数据不会改变
这是我的控制器
public function search_code(){
$this->load->library('pagination');
$param = new stdClass();
$param->item_code = $this->input->get('by_item_code');
$param->description = $this->input->get('by_description');
if (!isset($page) || $page == '') {
$page = 1;
}
$param->per_page = 50;
$param->limit = ($page - 1) * $param->per_page;
$paginate_url = base_url('warehouse/search_code?item_code='.$param->item_code.'&by_description='.$param->description.'&page='.($page+1));
$data['total_result'] = $this->m_stock->count_stock_search ($param);
$config['uri_segment'] = 3;
$config['num_links'] = 4;
$config['base_url'] = $paginate_url;
$config['total_rows'] = $data['total_result'];
$config['per_page'] = $param->per_page;
$config['use_page_numbers'] = TRUE;
$config['page_query_string'] = TRUE;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['item'] = $this->m_stock->search_code ($param);
$this->load->view('v_all_stocks', $data);
}
这是我的模特
function search_code($param){
$result = array();
$sql = "select ic.id, ic.item_code, ic.description, maxdt.maxdt, lc.balance,lc.dt,lc.createdate,lc.id_lines_code, io.ONHANDQTY ";
$sql .= "from tbl_item_code ic ";
$sql .= "left join ( tbl_lines_code lc inner join ( select id, max(createdate) maxdt from tbl_lines_code where active = 1 group by id ) maxdt ";
$sql .= "on lc.id = maxdt.id and lc.createdate = maxdt.maxdt ) on ic.id = lc.id ";
$sql .= "left join item_ostendo io on io.ITEMCODE = ic.item_code ";
$sql .= "where ic.active = 1 ";
if ($param->item_code != '') {
$sql .= "AND ic.item_code LIKE '%$param->item_code%' ";
}
if ($param->description != '') {
$sql .= "AND ic.description LIKE '%$param->description%' ";
}
$sql .= "group by ic.id order by ic.item_code ";
if ($param->limit > 0)
$sql .= " LIMIT ".$param->limit.", ".$param->per_page;
else
$sql .= " LIMIT ".$param->per_page;
$query = $this->db->query($sql);
if ($query->num_rows() > 0) {
$result = $query->result();
}
return $result;
}
和关于视图我检查它可以工作 但我不知道为什么我选择数字的链接,数据显示像最后一页,但链接的数量正在工作
答案 0 :(得分:0)
你需要改变你的:
$paginate_url = base_url('warehouse/search_code?item_code='.$param->item_code.'&by_description='.$param->description.'&page='.($page+1));
此:
$config['uri_segment'] = 3;
为offset子句定义该段。
我建议:
$query = "?item_code='.$param->item_code.'&by_description='.$param->description.'&page='.($page+1))";
$paginate_url = base_url('warehouse/search_code/page/').$query;
$config['uri_segment'] = 4;
将此作为抵消:
$param->limit = $this->uri->segment(4);
答案 1 :(得分:0)
您必须更改分页基本网址,如下所示:
$paginate_url = base_url('warehouse/search_code').'?item_code='.$param->item_code.'&by_description='.$param->description;