1

我有这样的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_kategorimaterialindex零件

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 ) ) 
4

3 回答 3

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();
于 2012-10-25T08:11:14.423 回答
0

echo $this->pagination->create_links();

于 2012-10-25T08:12:52.597 回答
0

在控制器中包含分页库

$this->load->library('pagination');

And alter a line in your controller to

$this->load->view('v/vkategorimaterial',$data);

这是对您Codeigniter 分页有用的链接:

于 2012-12-12T08:48:21.817 回答