在Codeigniter中搜索的分页不起作用

问题描述 投票:0回答:2

我在codeigniter中搜索分页时遇到问题

  • 选择其他页面链接时,URL不会更改
  • 选择其他链接时,数据不会更改

这是我的控制器

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;

}

和关于视图我检查它可以工作但我不知道为什么我选择数字的链接数据显示像最后一页但链接的数量正在工作

显示所有未搜索的数据链接显示如下enter image description here

当搜索显示像这样enter image description here,但当选择链接的数字2时它显示像这个enter image description here和数据是相同的每页

codeigniter pagination
2个回答
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); 

0
投票

您必须更改分页基本URL,如下所示:

    $paginate_url = base_url('warehouse/search_code').'?item_code='.$param->item_code.'&by_description='.$param->description;
© www.soinside.com 2019 - 2024. All rights reserved.