0

我正在使用每页 20 结果的 codeigniter 分页,但是当我单击分页平均页码时,它只得到两个结果,例如 2、3、4 以下是我的控制器

function restaurant_listing()
    {
        $config['base_url'] = base_url() . 'admin/restaurant/restaurant_listing/';
        //$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];
        //$config['base_url'] .= preg_replace('@/+$@','',dirname($_SERVER['SCRIPT_NAME'])).'/';
        $config['total_rows'] = $this->restaurant_model->record_count();
        $config['per_page'] = 20;
        $config['uri_segment'] = 4;
        $config['num_links'] = 10;
        $config['use_page_numbers'] = TRUE;
        $config['cur_tag_open'] = '<b>';
        $config['cur_tag_close'] = '</b>';

        $this->pagination->initialize($config);

        $page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
        $data["results"] = $this->restaurant_model->restlisting($config["per_page"], $page);
        $data["links"] = $this->pagination->create_links();

        $data['content'] = $this->load->view('admin/restaurant_listing', $data, true);
        $this->load->view('admin/template', $data); 
    }

我的视图文件包含

<div class="pagination"> <?php echo $links; ?> </div> 

我在这里显示分页

4

1 回答 1

0

也许可以修复您的代码我使用此代码进行分页

控制器代码

public restaurant_listing()
{

$restaurant=$this->uri->segment(4);

$limit_ti=20;
if(!$restaurant):
offset_ti = 0;
else:
$offset_ti = $restaurant;
endif;


$this->load->model('Restaurant_model');// call model
$this->load->library('pagination'); // call library

$query=$this->restaurant_model->restlisting($limit_ti,$offset_ti); // geting an article 

$total_page = $this->restaurant_model->record_count(); // count row

 /** Pagination **/
 $config['base_url'] = base_url().'admin/restaurant/restaurant_listing/'; 
 $config['total_rows'] =$total_page->num_rows();
 $config['per_page'] = 20; 
 $config['uri_segment'] = 4;
 $config['num_links'] = 10;
 $config['use_page_numbers'] = TRUE;
 $config['cur_tag_open'] = '<b>';
 $config['cur_tag_close'] = '</b>';

    $this->pagination->initialize($config);
    $data = array('query' => $query,'page'=>$restaurant);

    $data['content'] = 'admin/restaurant_listing';
    $this->load->view('template', $data);

}

型号代码

function restlisting($limit,$ofset){
$query=$this->db->query("select * from *name table* order by id ASC LIMIT $ofset,$limit");
return $query;
}

function record_count(){
$query=$this->db->query("select * from *name table*");
return $query;
}

查看代码

<div class="pagination"><?php echo $this->pagination->create_links(); // call the pagnation?></div>
于 2013-06-22T09:48:52.917 回答