1

i have view vkategorimaterial like this

<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(); ?>

then i made the controller named c_kategorimaterial here is the index part

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');

}

i want to make a pagination that showing 5 rows per page. and here is the model of m_kategorimaterial->get

 $this->db->order_by('Kode_Kategori_Material_Jasa','DESC');
    $query = $this->db->get('ms_kategori_material',5);
    return $query;

why does the pagination is not showing ? here is the result of 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 ) ) 
3
  • $config['base_url'] = base_url().'index.php/c_kategorimaterial/index/';
    – Deepak
    Oct 25, 2012 at 8:03
  • @deepak oh thank you deepak, i have corrected the thread above and my code, and it still doesn't make my pagination showed. where did i go wrong ?
    – Cignitor
    Oct 25, 2012 at 8:06
  • make sure records are more than $config['per_page'] = 5; Oct 25, 2012 at 8:19

3 Answers 3

1

Try this block

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');

}

And in your view try this,

echo $this->pagination->create_links();
9
  • i've tried your index, and adding echo $this->pagination->create_links(); and the pagination still not showing
    – Cignitor
    Oct 25, 2012 at 8:15
  • in that case your $data['rows'] does not have any records. Try print_r($data['rows']) see if it prints anything
    – Deepak
    Oct 25, 2012 at 8:17
  • it shows blank white screen with 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 ) )
    – Cignitor
    Oct 25, 2012 at 8:18
  • what is $query->num_rows() this value ?
    – Deepak
    Oct 25, 2012 at 8:20
  • it shows 3 because there's only 3 records in my DB do i have to add more record to make it displayed ?
    – Cignitor
    Oct 25, 2012 at 8:21
0

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

3
  • do i need to make more record like 10 record to make it appear ?
    – Cignitor
    Oct 25, 2012 at 8:16
  • Your per page post is set to 5. So you need atleast 6 post to appear the links.
    – itachi
    Oct 25, 2012 at 8:28
  • i change the config into $config['per_page'] = 2; and the model into $query = $this->db->get('ms_kategori_material',2); and there's 3 record in the database. the pagination is not showing
    – Cignitor
    Oct 25, 2012 at 8:31
0

Include pagination library in controller

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

And alter a line in your controller to

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

Here is helpful link for you Codeigniter Pagination:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.