0

ページ 20 ごとの結果で codeigniter ページネーションを使用していますが、2、3、4 のようなページネーションの平均ページ番号をクリックすると、2 つの結果しか得られません。以下は私のコントローラーです。

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 に答える