Codeigniter 我的分页不起作用

Codeigniter 我的分页不起作用,codeigniter,pagination,Codeigniter,Pagination,为什么我的分页在另一个函数中不起作用它起作用了。它显示分页的链接,但第一页显示所有数据。另一页的链接不显示数据 public function index(){ $this->load->library('pagination'); $page = $this->uri->segment(2); $param = new stdClass(); if (!isset($page) || $page == '') { $pag

为什么我的分页在另一个函数中不起作用它起作用了。它显示分页的链接,但第一页显示所有数据。另一页的链接不显示数据

public function index(){
    $this->load->library('pagination');
    $page = $this->uri->segment(2);
    $param = new stdClass();
    if (!isset($page) || $page == '') {
        $page = 1;
    }
    $param->per_page = 5;
    $param->limit = ($page - 1) * $param->per_page;

    $paginate_url = site_url('warehouse');

    $data['total_result'] = $this->m_stock->count ($param);

    $config['uri_segment'] = 2;
    $config['num_links'] = 3;
    $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'] = FALSE;
    $this->pagination->initialize($config);
    $data['pagination']   = $this->pagination->create_links();

    $data['item'] = $this->m_stock->get_item_code($param);
    $this->load->view('v_all_stocks', $data);
}

此函数用于计数数据库

function count(){
  $this->db->select("*");
  $this->db->from("tbl_item_code");
  $this->db->where('active', '1');
  $num_results = $this->db->count_all_results();
  return $num_results;
}
试试这个:

public function index(){
    $this->load->library('pagination');
    $page = $this->uri->segment(2);
    $param = new stdClass();
    if (!isset($page) || $page == '') {
        $page = 1;
    }
    $param->per_page = 5;
    $param->limit = ($page - 1) * $param->per_page;

    $paginate_url = site_url('warehouse');
    $results = $this->m_stock->get_item_code($param);  //get the db query object here
    $data['total_result'] =  $results->num_rows(); //get the number of results for this query

    $config['uri_segment'] = 2;
    $config['use_page_numbers'] = TRUE;  //add this line if you wnat to use page numbers instead of offset in url
    $config['num_links'] = 3;
    $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'] = FALSE;
    $this->pagination->initialize($config);
    $data['pagination']   = $this->pagination->create_links();

    $data['item'] = $results->result();  //get the results
    $this->load->view('v_all_stocks', $data);
}
在模型代码中:

function get_item_code($param){
    $result = array();
    $sql = "select ic.id, ic.item_code, ic.description, maxdt.maxdt, lc.balance ";
    $sql .= "from tbl_item_code ic ";
    $sql .= "left join ( tbl_lines_code lc inner join ( select id, max(dt) maxdt from tbl_lines_code group by id ) maxdt ";
    $sql .= "on lc.id = maxdt.id and lc.dt = maxdt.maxdt ) on ic.id = lc.id ";
    $sql .= "where ic.active = 1";
    if ($param->limit > 0)
        $this->db->limit($param->per_page, $param->limit);
    else 
        $this->db->limit($param->per_page);
     return $this->db->query($sql);  //change it to return the db query object

}

显示您获得的输出显示所有数据结果不单独页面
$data['total_result']=$this->m_stock->count($param)此计数函数返回什么?是的,它是数据库中的计数数据,但我更改为$data['total_result']=$this->m_stock->Count()此函数计数它仍然无法工作,并在查看页面中显示错误它正在工作,但不是单独的数据它在一个页面中显示255个总数据