简体   繁体   中英

Pagination link not work properly

I trying to get all records from my table (tbl_room_image) by a specific "record id" and show them in my view with a pagination i can get all records perfectly with limit but my pagination link not working to see next record data. For example, I set the limit 4 so when page loaded i can only see first 4 records not others plz help.

Here is my controller:

    function addRoomImage($roomid, $limit = '', $offset = 0){
        $limit = 4;
        $offset = $this->uri->segment(3);

        $config['base_url'] = base_url().'config/addRoomImage/'.$roomid;
        $config['total_rows'] = $this->config_mdl->count_room_image($roomid);
        $config['per_page'] = $limit;
        $config['uri_segment'] = 3;

        $data['imageData'] = $this->config_mdl->get_roomImage($roomid, $limit, $offset);
        $this->pagination->initialize($config);

        $data['imageid'] = $this->config_mdl->get_roomById($roomid);
        $data['pagination'] = $this->pagination->create_links();
        $data['main_content'] = 'config/addRoomImage';
        $this->load->view('_base/layout',$data);
    }

Here is My Model:

    function count_room_image($roomid)
    {
        $this->db->where('room_id', $roomid);
        return $this->db->count_all_results('tbl_room_image');
    }

    function get_roomById($roomid)
    {
        return $this->db->get_where('tbl_room_info', array('room_id' => $roomid))->result();
    }

    function get_roomImage($roomid, $limit, $offset)
    {
        $this->db->select('room_name,room_image');
        $this->db->from('tbl_room_image');
        $this->db->join('tbl_room_info',  'tbl_room_info.room_id = tbl_room_image.room_id', 'inner');
        $this->db->where('tbl_room_image.room_id', $roomid);
        $this->db->limit($limit, $offset);
        return $this->db->get()->result();
    }

ok I find out the problem it's in uri->segment.

       $offset = $this->uri->segment(4);
       $config['uri_segment'] = 4;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM