基本上我使用带有Codeigniter的Bootstrap主题
这是我的控制器代码。导师是数据库中的表格。
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>
但它出错了。我怎么修改它? 谢谢你们。
答案 0 :(得分:0)
尝试使用
foreach($ query-&gt; result()为$ row)
而不是foreach($ record as $ row)