分页与在Codeigniter中搜索不工作 [英] Pagination with search in Codeigniter is not working
问题描述
我在codeigniter中搜索时遇到了一个问题
-
选择其他网页链接时, p>
-
选择其他链接时数据不会更改
这是我的控制器
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。 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。=其中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;
}
和关于视图我检查它可以工作
但我不知道为什么我选择数字的链接显示像最后一页,但链接的数量是工作
显示所有数据未搜索链接显示像这样
当搜索显示为这样,数据每页都相同
您必须更改分页基本网址如下:
$ paginate_url = base_url 'warehouse / search_code')。'?item_code ='。$ param-> item_code。'& by_description ='。$ param-> description;
I have a problem in pagination with search in codeigniter
URL is not change when select the other page link
the data is not change when select the other link
This my controller
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);
}
This my model
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;
}
and about view i checked it's can working but i don't know why i select the link of number the data is show like the last page but the number of link is working
Show all data not search yet the link show like this
when search show like this but when select number 2 of link it's show like this and the data is same every page
You have to change paging base url as below :
$paginate_url = base_url('warehouse/search_code').'?item_code='.$param->item_code.'&by_description='.$param->description;
这篇关于分页与在Codeigniter中搜索不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!