Php Codeigniter:不使用表库对数据进行分页
基本上我使用引导主题与Codeigniter 这是我的控制器代码。tutors是数据库中的表Php Codeigniter:不使用表库对数据进行分页,php,codeigniter,pagination,Php,Codeigniter,Pagination,基本上我使用引导主题与Codeigniter 这是我的控制器代码。tutors是数据库中的表 public function index() { $this->load->library('pagination'); $config['base_url'] = 'http://localhost:8888/bootstrap/index.php/frontpage/index'; $config['total_rows'] = $this->db-&g
public function index() {
$this->load->library('pagination');
$config['base_url'] = 'http://localhost:8888/bootstrap/index.php/frontpage/index';
$config['total_rows'] = $this->db->get('tutors')->num_rows();
$config['per_page'] = 6;
$config['num_links'] = 10;
$this->pagination->initialize($config);
$data['records'] = $this->db->get('tutors', $config['per_page'], $this->uri->segment(3));
$this->load->view('include/header');
$this->load->view('frontpage', $data);
$this->load->view('include/footer');
}
我想自定义视图,如下所示
<div class="container" style="text-align: center;">
<?php
$i=0;
foreach($records as $row) :
if ($i%3==0) { ?>
<div class="row">
<div class="col-md-4">
<h1><?php echo $row->title; ?></h1>
<h2><?php echo $row->id; ?></h2>
</div>
<?php
} else {
?>
<div class="col-md-4">
<h1><?php echo $row->title; ?></h1>
<h2><?php echo $row->id; ?></h2>
</div>
<?php
if ($i%3==2) {
echo "</div>";
}
}
$i++;
endforeach;
?>
</div>
<div class="container">
<?php echo $this->pagination->create_links(); ?>
</div>
但它会出错。如何修改它?
谢谢大家。尝试使用
foreach($query->result()作为$row)
没有使用foreach($records as$row)而是遇到了一个PHP错误严重性:注意消息:试图获取非对象文件名的属性:views/frontpage.phpoh,是否未声明变量$row?