我有这样的vkategorimaterial
<table border="1">
<tr>
<td colspan="4">Tampilkan<?php
echo form_open('c_kategorimaterial/cari');
echo nbs();$intext=array('name' => 'cari', 'class' => 'GUI');
echo form_input($intext);
echo nbs(); $inbutton=array('value' => 'Cari', 'class' => 'button');
echo form_submit($inbutton);
echo form_close();
?></td>
</tr>
<tr>
<td colspan="4"><a href="<?php echo base_url(); ?>index.php/c_kategorimaterial/tambah"><img class ="create" src="<?php echo base_url();?>img/create.png"></a></td>
</tr>
<tr>
<td>Nomor</td>
<td>Kode Kategori Material / Jasa</td>
<td>Nama Material / Jasa</td>
<td>Perintah</td>
</tr>
<?php if ( !empty($rows) )
{
$no = 1;
foreach ($rows as $row) { ?>
<tr id="row">
<td><?php echo $no;?></td>
<td><?php echo $row->Kode_Kategori_Material_Jasa;?></td>
<td><?php echo $row->Nama_Material_Jasa;?></td>
<td> <a href="<?php echo site_url('c_kategorimaterial/ubah/'.$row->Kode_Kategori_Material_Jasa.'/'.$row->Nama_Material_Jasa);?>"><img class="perintah" src="<?php echo base_url(); ?>img/update.png"></a><a href="<?php echo site_url('c_kategorimaterial/hapus/'.$row->Kode_Kategori_Material_Jasa);?>" onclick="return confirm('akan dihapus, anda yakin ?');"><img class="perintah" src="<?php echo base_url(); ?>img/delete.png"></a></td>
</tr>
<?php
$no++;
}
}
else { ?>
<tr id="row">
<td colspan="6" align="center">Tabel Kosong</td>
</tr>
<?php
}
?>
</table>
<?php echo $this->pagination->create_links(); ?>
然后我将名为c_kategorimaterial
的控制器设为index
部分
function index()
{
$query = $this->m_kategorimaterial->get();
$config['base_url'] = base_url().'index.php/c_kategorimaterial/index/';
$config['total_rows'] = $query->num_rows();
$config['per_page'] = 5;
$this->pagination->initialize($config);
$data['rows'] = $query->result();
$data['title'] = 'QB Kategori Material';
$this->load->view('menu',$data);
$this->load->view('v/vkategorimaterial');
}
我想制作一个每页显示5行的分页。这是m_kategorimaterial->get
$this->db->order_by('Kode_Kategori_Material_Jasa','DESC');
$query = $this->db->get('ms_kategori_material',5);
return $query;
为什么分页没有显示?这是print_r($data['rows']);
Array ( [0] => stdClass Object ( [Kode_Kategori_Material_Jasa] => KKMJ006 [Nama_Material_Jasa] => Biji ) [1] => stdClass Object ( [Kode_Kategori_Material_Jasa] => KKMJ004 [Nama_Material_Jasa] => Teneh ) [2] => stdClass Object ( [Kode_Kategori_Material_Jasa] => KKMJ001 [Nama_Material_Jasa] => Air ) )
答案 0 :(得分:1)
试试这个块
function index()
{
$query = $this->m_kategorimaterial->get();
$config['base_url'] = base_url().'index.php/c_kategorimaterial/index/';
$config['total_rows'] = $query->num_rows();
$config['per_page'] = 5;
$data['rows'] = $query->result();
$this->pagination->initialize($config);
$this->load->vars($data); // !!!
$data['title'] = 'QB Kategori Material';
$this->load->view('menu',$data);
$this->load->view('v/vkategorimaterial');
}
在你看来试试这个,
echo $this->pagination->create_links();
答案 1 :(得分:0)
echo $this->pagination->create_links();
答案 2 :(得分:0)
在控制器中包含分页库
$this->load->library('pagination');
And alter a line in your controller to
$this->load->view('v/vkategorimaterial',$data);
以下是Codeigniter Pagination的有用链接: