0

我是 codeigniter 的新手,我通过从 Category Id 获取查询结果来使用 codeigniter 分页,但页面总是从第 2 页开始。如何修复分页以将起始页设置为第 1 页?

public function kategori($kat=''){

$config['base_url'] = base_url().'index.php/lowongan/kategori/'.$kat;
$data['db']=$this->query->katPostingan($kat);       
$config['total_rows'] = $data['db']->num_rows(); 
$config['per_page'] = 1;    
$config['uri_segment'] = 4;
$this->pagination->initialize($config);
$data2['paging'] = $this->pagination->create_links();

$page = ($this->uri->segment($config['uri_segment'])) ? $this->uri->segment($config['uri_segment']) : 0;
$data2['records'] = $this->query->katPos($kat, $config['per_page'], $page);

$this->load->view( 'user/hal_kategori',$data2);
    }

和我的模特

public function katPos($kat='',$limit,$start){
$this->db->where("id_kat", $kat);
$this->db->limit($limit,$start);
    $query = $this->db->get("showKat");
    return $query;
}

    public function katPostingan($kat=''){
            $this->db->where("id_kat", $kat);
            $query = $this->db->get("showKat");
        return $query;
    }  
4

1 回答 1

0

尝试不同的解决方法,

控制器(索引())

        $this->load->library('pagination');
        $config['base_url'] = site_url().'classname/index';
        $config['per_page'] = $this->config->item('pagination_number');
        $config['uri_segment'] = 4;
        $data['count']=$this->example_model->count();
        $config['total_rows'] =$data['count'];
        $data['classname']=$this->example_model->getall($this->config->item('pagination_number'),$this->uri->segment(4));
        $this->pagination->initialize($config); 
        $data['page_link']=$this->pagination->create_links();


        $this->load->view('users/classname.php',$data);

模型

function getall($num,$offset)
{
    $this->db->from('table_name');
    $this->db->limit($num,$offset);
    $query = $this->db->get();
    return $query->result_array();
}
function count()
{
    $this->db->from('table_name');
    $query = $this->db->get();
    $rowcount = $query->num_rows();
    return( $rowcount);
}

看法

<div class="pagination"> <?php echo $page_link;?> </div>
于 2013-08-19T13:46:35.563 回答