Seach

pagination example in codeigniter

view page

<div id="item">
LIST
</div>
<table >
<th>Product</th>
<th>Quantity</th>
<th>Price</th>
<th>Stock</th>
<th>Image</th>
<th>Action</th>
<?php
if(isset($result))
{
foreach ($result as $data)
{
?>
<tr>
<td>
    <input type="text" name="name" value="<?php echo $data['name'];?>">
</td>
<td>
    <input type="text" name="qty" value="<?php echo $data['qty'];?>" style="width: 40px;">

</td>
<td>
    <input type="text" name="price" value="<?php echo $data['price'];?>" style="width: 80px;">
</td>
<td>
        <input type="text" name="price" value="<?php echo $data['stock'];?>" style="width: 40px;">


</td>
<td>
    <img src="<?php echo base_url().''.$data['image'];?>" width="70" height="100" title="Picture cannot be changed">
</td>
<td>
    <a href="<?php echo $data['id'];?>" id="edit"  ><img src="http://localhost/backery/assets/images/edit.jpg" height="20" width="20"></a>
    &nbsp;&nbsp;
    <a href="<?php echo $data['id'];?>" id="delete"  ><img src="http://localhost/backery/assets/images/delete.jpg" height="20" width="20"></a>
   
</td>
</tr>
<?php
}} ?>
</table>
<div id="link">
<?php echo $link;?>
</div>

controller

public function home()
{
$this->session_alive();
$total=$this->admin_model->count();
$config['total_rows']=$total;
$config['per_page']=2;
$config['base_url']=  site_url().'/admin/home/';
$data['result']=$this->admin_model->list_items(2,$this->uri->segment(3));
if(count($data)>=1)
{
$this->pagination->initialize($config);
$data['link']=$this->pagination->create_links();

$this->load->view('home',$data);
}
else
{
$this->load->view('home');
}
}

model

//used to paginate products
public function list_items($limit,$segment)
{
    $query=$this->db->get('product',$limit,$segment);
    return $query->result_array();
}
//used to find the total
public function count()
{
    return $this->db->count_all('product');
}