分页不起作用 - 代码点火器

时间:2014-08-15 04:14:37

标签: php codeigniter pagination

为什么我的分页不起作用? 为此功能坚持24小时。我在数据库查询中错了吗?我不明白我的代码有什么问题。

这是控制器:

function search()
{   
    $category_type = $this->input->post('category_type');
    $data['result'] = $this->Grabber_model->get_data($category_type);

    $config = array();
    $config['base_url'] = base_url() . "grabber/search/index/";
    $config['total_rows'] = $this->Grabber_model->count();
    $config['per_page'] = 20;
    $config['uri_segment'] = 4;
    $config['num_links'] = 2;
    $config['use_page_numbers']  = TRUE;
    $config['full_tag_open'] = "<ul class='pagination'>";
    $config['full_tag_close'] ="</ul>";
    $config['num_tag_open'] = '<li>';
    $config['num_tag_close'] = '</li>';
    $config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
    $config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
    $config['next_tag_open'] = "<li>";
    $config['next_tagl_close'] = "</li>";
    $config['prev_tag_open'] = "<li>";
    $config['prev_tagl_close'] = "</li>";
    $config['first_tag_open'] = "<li>";
    $config['first_tagl_close'] = "</li>";
    $config['last_tag_open'] = "<li>";
    $config['last_tagl_close'] = "</li>";

    $this->pagination->initialize($config);
    $data["links"] = $this->pagination->create_links();

    $this->load->view('global_h');
    $this->load->view('grabber_view', $data);
    $this->load->view('global_f');
}

继承模特:

function get_data($category_type) {
    $this->load->database();
    $this->db->select('*');
    $this->db->from('products');
    $this->db->where('category_type', $category_type);
    $this->db->order_by('create_at','desc');
    $this->db->limit(50);

    $query = $this->db->get();
    return $query->result();
}

这就是观点:

<div class="center">
  <?php foreach($result as $row){ ?>
  <div style="margin:0 10px 10px 0;float:left;width:250px" class="img-thumbnail" >
     <img data-original="http://static04-id.zalora.com<?php echo $row->image_full; ?>" width="240px" height="346px" class="lazy" /><br>
     Brand: <?php echo $row->brand; ?><br>
     SKU: <?php echo $row->sku; ?><br>
  </div>
  <?php } ?>
  <div style="clear:both;text-align:center;"><?php echo $links; ?></div>
</div>

希望你们能解决我的问题,谢谢!

1 个答案:

答案 0 :(得分:0)

不知道分页不工作意味着什么(如果可以,请解释更多)但根据我的观察,你没有在$ config数组中添加偏移量,如

  

$ config ['offset'] ='uri_segment或0'

你必须在你的查询中使用限制方法,如

  

limit(50,$ offset);