如何解决分页第二页链接显示细节?

时间:2017-05-16 17:07:18

标签: php codeigniter

我在CodeIgniter中做分页。 数据正确加载,但当我点击下一步时,它将显示一个空白页面。

一切都配置正确。 加载的分页库也。 但是这个链接不起作用。

我的模特是:

public function record_count_apartment() {
        return $this->db->count_all("apartments");
    }

function get_apartment_details($limit, $start) 
    {       $this->db->limit($limit, $start);
            $this->db->select('*');
            $this->db->from('apartments');
            $query = $this->db->get();
            return $query->result();
    }

我的控制器是:

$config = array();
$config["base_url"] = base_url() . "search";
$config["per_page"] = 1;
$config["uri_segment"] = 2;
$config['cur_tag_open'] = '&nbsp;<a class="current">';
$config['cur_tag_close'] = '</a>';
$config['num_links'] = 2;
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$config['use_page_numbers'] = TRUE;
$config["total_rows"] = $this->get_search_details_model->record_count_apartment();
$this->pagination->initialize($config);
$page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
$data['apartments'] = $this->get_search_details_model->get_apartment_details($config["per_page"], $page );
$data["links"] = $this->pagination->create_links();
//print_r($data);
$this->layouts->view('user/user_apartments_view', array('left_sidebar' => 'sidebar/left_sidebar','right_sidebar' => 'sidebar/right_sidebar'),$data,TRUE);

我的观点是:

<div class="container">


  <div class="container col-lg-12 " style="background-color:#49BF4C; margin-top:0.5em;">
    <div class="col-lg-12">
      <strong> <h3 style="color:white; font-weight:900; font-size:1.5em; text-align:center; ">Apartments</h3> </strong>
    </div>
  </div>


  <?php

   foreach( $apartments as $apartment) { ?>


    <div class="col-lg-3">

      <?php echo $apartment->a_name;?> <br>
      <?php echo $apartment->a_cityname;?> <br>
      <?php echo $apartment->a_desc;?> <br>

    </div>

    <?php }  ?>

    <div class="col-lg-12">
      <?php echo $links; ?>
    </div>

</div>

2 个答案:

答案 0 :(得分:1)

如果您使用的是bootstrap框架,请使用以下针对bootstrap定制的分页代码: -

        $config["base_url"] = base_url() . "search";


        $config['total_rows'] = $this->get_search_details_model->record_count_apartment();


        $config['per_page'] = 10;

        $config['num_links'] = 2;

        $config['uri_segment'] = 3;

        $config['full_tag_open'] = '<ul class="pagination pagination-sm no-margin pull-right">';

        $config['full_tag_close'] = '</ul>';

        $config['num_tag_open'] = '<li>';

        $config['num_tag_close'] = '</li>';

        $config['cur_tag_open'] = '<li class="active"><a href="#"><b>';

        $config['cur_tag_close'] = '</b></a></li>';

        $config['prev_tag_open'] = '<li>';

        $config['prev_tag_close'] = '</li>';

        $config['next_tag_open'] = '<li>';

        $config['next_tag_close'] = '</li>';

        $config['page_query_string'] = TRUE;

        $config['query_string_segment'] = 'page';

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

        $data['links'] = $this->pagination->create_links();

        $data['apartments'] = $this->get_search_details_model->get_apartment_details($config["per_page"], $page );
        $this->layouts->view('user/user_apartments_view', array('left_sidebar' => 'sidebar/left_sidebar','right_sidebar' => 'sidebar/right_sidebar'),$data,TRUE);

答案 1 :(得分:1)

我认为问题在于您的分页库配置

$config["base_url"] = base_url() . "search/index";
$config["per_page"] = 1;
$config["uri_segment"] = 3;

而不是上面的代码,你应该写

SELECT  Value, RecordId,GridData.FormId,GridName,ExampleField
FROM GridData
Join FormList  On GridData.FormID = FormList.FormID
Join FormList A On FormList.JobID = A.FormID
JOIN FormData On A.JobID = FormData.FormID
Where FormData.DataItemName = 'JobProductName';