分页链接无法正常工作

时间:2014-10-20 11:18:56

标签: php codeigniter pagination codeigniter-2

我试图通过特定的"记录ID"从我的表(tbl_room_image)获取所有记录。并在我的视图中以分页显示它们我可以完美地获得所有记录的限制但我的分页链接无法查看下一个记录数据。例如,我设置了限制4,所以当页面加载时我只能看到前4个记录而不是其他plz帮助。

这是我的控制器:

    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);
    }

这是我的模特:

    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();
    }

1 个答案:

答案 0 :(得分:0)

好的,我发现了它在uri->段中的问题。

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