Skip to content Skip to sidebar Skip to footer

Pagination Is Not Working Properly

This is my pagination code.In my code I am going to display 20 images in each page,But I am getting all images in first page and if I click page2 again the same images were display

Solution 1:

In my code I just changed the session variable.Then everything its working fine.

Controller

publicfunctiononSectorClick() {

            $id = $_GET["id"];

            $this->session->set_userdata('sub1_id', $_GET['id']);

            $this->onSectorClickCopy();
        }

        publicfunctiononSectorClickCopy(){
            if ($this->session->userdata('log_in') == TRUE) {
                $id = $this->session->userdata('id');
                $this->load->model('cart_model');
                $data["count"] = $this->cart_model->count_rows($id);
            }



            $data['ListMenuLevel1'] = $this->Categories_model->listsector1();

            $config = array();
            $config["base_url"] = base_url() . "index.php/welcome/onSectorClickCopy";
            $total_row = $this->productdisplay_model->record_count($this->session->userdata('sub1_id'));
            $config['total_rows'] = $total_row;
            $config['per_page'] = 20;
            //$config['uri_segment'] = 3;$config['use_page_numbers'] = TRUE;
            //$config['page_query_string'] = TRUE;//$config['reuse_query_string'] = FALSE;$config['num_links'] = 1;
            $config['cur_tag_open'] = '&nbsp;<a class="current">';
            $config['cur_tag_close'] = '</a>';
            $config['next_link'] = 'Next';
            $config['prev_link'] = 'Previous';
            $this->load->library('pagination');
            $this->pagination->initialize($config);
            /* if($this->uri->segment(3)){
              $page = ($this->uri->segment(3)) ;
              }
              else{
              $page = 1;
              } */$page = ($this->uri->segment(3) != '' ? $this->uri->segment(3) : 1);
            //$offset = $config['per_page']*$page;$offset = (($config['per_page']) * ($page - 1));
            $limit = $config['per_page']+1;
            $data['sub1products'] = $this->productdisplay_model->sub1Productsmenu($this->session->userdata('sub1_id'),$limit, $offset);
            $str_links = $this->pagination->create_links();
            $data["links"] = explode('&nbsp;', $str_links);

            $this->load->view('productlist', $data);

        }

Model

publicfunctionrecord_count($id) {
        $this->db->select('*');
        $this->db->from('sub1_category');
        $this->db->where('main_categoryid_fk', $id);
        $this->db->order_by("sub1_category.main_categoryid_fk ");
        $query = $this->db->get();
        return$query->num_rows();

    }


    publicfunctionsub1Productsmenu($id,$limit, $offset){

        $this->db->select('*');
        $this->db->from('sub1_category');
        $this->db->where('main_categoryid_fk', $id);
        $this->db->order_by("sub1_category.main_categoryid_fk ");
        $this->db->limit($limit, $offset);
        return$this->db->get()->result();

    }

    publicfunctionsub1Productfetch($id) {


        $query = $this->db->select('product_image,sub1_category_name,product_description');
        $this->db->from('sub3_category');
        $this->db->join('sub2_category', 'sub3_category.sub2_categoryid_fk=sub2_category.id', 'left');
        $this->db->join('sub1_category', 'sub2_category.sub1_categoryid_fk=sub1_category.id', 'left');
        $this->db->join('maincategory', 'sub1_category.main_categoryid_fk=maincategory.id', 'left');
        $this->db->where('sub1_category.id',$id);

        //$this->db->order_by('rand()');$this->db->limit(1);


        return$this->db->get()->result();

    }

Solution 2:

As I see in your code:

publicfunctionsub1Productsmenu($id,$limit, $offset){
    return$this->db->where('main_categoryid_fk',$id)->get('sub1_category')->result();
      $this->db->where("sub1_category.id between '$offset' and '$limit'");
}

You have wrong ";" in second line. It's alway return all recods because the WHERE condition not apply.

Post a Comment for "Pagination Is Not Working Properly"