|
大家好,由于刚学习CI,有个关于分页的问题请大家帮帮忙。
我需要制作分页的功能,目前已经可以抓取资料的总数以及每一页显示的数量,但是我的VIEWS却抓不到资料,每一页都显示所有的资料,请问大家我models应该怎么写
CONTROLLERS
public function test() {
//裝載類文件
$this->load->library('pagination');
$this->load->helper('url');
//每頁顯示30筆
$page_size = 30;
$config['base_url'] = site_url('/Home/test/');
//全部數量
$mycount = count($this->M_firm->test());
$config['total_rows'] = $mycount;
//print_r($config['total_rows']);
//exit();
//每頁顯示數量
$config['per_page'] = $page_size;
//頁面按鈕
$config['first_link'] = FALSE;
$config['prev_link'] = '上一頁';
$config['uri_segment'] = 3; //資料的偏移頁
$config['use_page_numbers'] = TRUE;
$config['next_link'] = '下一頁';
$config['last_link'] = FALSE;
$config['display_pages'] = FALSE;
$this->pagination->initialize($config);
$offset = intval($this->uri->segment(3)); //與$config['uri_segment'] = 3對應
//echo $sql;
$data['links'] = $this->pagination->create_links();
$this->load->view('test', $data);
}
MODELS
/* 測試分頁用 */
function test() {
$this->db->from('firm');
//$this->db->limit(50, 0);
$this->db->where('display=', 1);
$this->db->where('firmaddressmap!=', "");
$this->db->where('businesshours!=', "");
$this->db->where('offday!=', "");
$this->db->where('web!=', "");
$this->db->where('fb!=', "");
$this->_firmaddress_x_y_db();
$this->db->order_by('firmid', 'ASC');
//$this->db->where('shelves_c >=', time());
//$this->db->order_by('rand()');
$row_test = $this->db->get()->result_array();
return $row_test;
}
VIEWS
<div class="pager nav nav-pills" role="tablist">
<ui>
<li>
<?= $links ?>
</li>
</ui>
</div>
<?php foreach ($this->M_firm->test() AS $_data): ?>
<div class="col-lg-3 col-md-6 col-sm-6 col-xs-12 item">
<div class="mainPushfirm">
<h5 style="margin: 0px;font-weight: bold;"><?php echo mb_substr($_data['firmfname'], 0, 16, "UTF-8"); ?></h5
</div>
</div>
<?php endforeach; ?> |
|