为什么我的分页没有在下一页显示其他数据

时间:2019-08-09 09:44:59

标签: php html codeigniter bootstrap-4

当我单击下一页时,我的分页页面没有显示其他数据。当我转到下一页时,该页面仅显示相同的数据。返回上一页与之相同,显示相同的数据。

我的代码在哪里出错?

我正在使用带有Bootsrap的Codeigniter框架。

这是我的产品型号

public function get_all_product(){
        $this->db->select('products.');
        $this->db->from('products');
        //$this->db->join('brand');
        $this->db->join('category');
        $this->db->order_by('RAND()');
        $query = $this->db->get();
        return $query->result();
    }

public function list_page_product($limit,$offset){
        $this->load->database();
        $this->db->order_by('id','desc');
        $query = $this->db->get('products',$limit,$offset);
        return $query->result();
    }

这是我的控制器

public function product(){
        $query2 = $this->db->query("select * from products");
        foreach ($query2->result_array() as $row2)
            {
                $idp[] = $row2['id'];
                $pdc[] = $row2['p_disc'];
                $dc[] = $row2['disc'];
                $stc[] = $row2['st_disc'];
                $edc[] = $row2['ed_disc'];
                $stck[] = $row2['stock'];
            }

        $this->Product_model->edit_product_disc($idp,$pd,$d,$st,$ed);

        $data['title'] = $this->Seo_model->get_setting();
        $data['description'] = $this->Seo_model->get_setting();
        $data['keyword'] = $this->Seo_model->get_setting();

        $data['list_categ'] = $this->Categ_model->list_category();     

        $data['list_products'] = $this->Product_model->get_all_product();

        $limit = 10;
        if(empty($offset)){ $offset = 0;}
        $config['first_link'] = 'Back to First Page';
        $config['first_tag_open'] = '<li class="paginat">';
        $config['first_tag_close'] = '</li>';

        $config['last_link'] = 'Last Page';
        $config['last_tag_open'] = '<li class="paginat">';
        $config['last_tag_close'] = '</li>';

                    // Next Link
        $config['next_link'] = 'Next';
        $config['next_tag_open'] = '<li class="paginat">';
        $config['next_tag_close'] = '</li>';

        // Previous Link
        $config['prev_link'] = 'Before';
        $config['prev_tag_open'] = '<li class="paginat">';
        $config['prev_tag_close'] = '</li>';

        // Current Link
        $config['cur_tag_open'] = '<li class="activepaginat">';
        $config['cur_tag_close'] = '</li>';

        // Digit Link
        $config['num_tag_open'] = '<li class="paginat">';
        $config['num_tag_close'] = '</li>';

        $data['list_products'] = $this->Product_model->list_page_product($limit,$offset);
        $config['base_url'] = base_url().'dashboard/product/';
        $config['total_rows'] = $this->Product_model->num_rows_product();
        $config['per_page'] = $limit;
        $config['uri_segment'] = 4;
        $this->pagination->initialize($config);   

        if ($this->agent->is_mobile()){
            $this->load->view('xxx/xxx',$data);
        }else{
            $this->load->view('xxx/xxx',$data);
        } 

    }

1 个答案:

答案 0 :(得分:1)

因为未在功能产品中调用/设置偏移量

public function product($offset = 0){

不要调用 get_all_product ,因为它可能会与 list_page_product

崩溃