【发布时间】:2016-10-21 01:52:00
【问题描述】:
我在 CI 3.0 中启动了一个 Web 应用程序,一切正常,我的分页工作正常,但是有一个我无法解决的问题...
我的模特
//Model
function jumlah(){
return $this->db->count_all('buku');
}
function fetch_buku($limit,$start){
$this->db->limit($limit,$start);
$query=$this->db->get('buku');
if($query->num_rows()>0){
foreach ($query->result() as $row) {
$data[]=$row;
}
return $data;
}
return false;
}
我的控制器
//Controller
function index(){
//load data
$data['title']="Data Buku";
$config['base_url']=site_url('anggota/index/');
$total_row=$this->m_buku->jumlah();
$config['total_rows']=$total_row;
$config['per_page']=$this->limit;
$config['use_page_numbers']=TRUE;
$config['uri_segment']=3;
$this->pagination->initialize($config);
$page=($this->uri->segment(3)) ? $this->uri->segment(3):0;;
$data['buku']=$this->m_buku->fetch_buku($config['per_page'],$page);
$data['pagination']=$this->pagination->create_links();
$data['message']='';
$this->template->display('buku/index',$data);
}
我的看法
//View
<?php echo $message;?>
<Table class="table table-striped">
<thead>
<tr>
<td>No.</td>
<td>Image</td>
<td>Kode Buku</td>
<td>Judul</td>
<td>Pengarang</td>
<td>Klasifikasi</td>
<td colspan="2"></td>
</tr>
</thead>
<?php $no=0; foreach($buku as $row ): $no++;?>
<tr>
<td><?php echo $no;?></td>
<td><img src="<?php echo base_url('assets/img/'.$row->image);?>" height="100px" width="100px"></td>
<td><?php echo $row->kode_buku;?></td>
<td><?php echo $row->judul;?></td>
<td><?php echo $row->pengarang;?></td>
<td><?php echo $row->klasifikasi;?></td>
<td><a href="<?php echo site_url('buku/edit/'.$row->kode_buku);?>"><i class="glyphicon glyphicon-edit"></i></a></td>
<td><a href="#" class="hapus" kode="<?php echo $row->kode_buku;?>"><i class="glyphicon glyphicon-trash"></i></a></td>
</tr>
<?php endforeach;?>
</Table>
<?php echo $pagination;?>
我的问题是当我加载其他页面时,该页面上无法显示数据。但数据可以显示在第一页。
【问题讨论】:
标签: php codeigniter pagination