CodeIgniter Forums

Full Version: Pagination modification
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This is my views:

PHP Code:
    <table class="table table-striped table-bordered bootstrap-datatable datatable">
        <
tr>
            <
th>ID</th>
            <
th>Product Name</th>
            <
th>Flat Package Code</th>
            <
th>Square Package Code</th>
            <
th>Plastics Package Code</th>
            <
th>Category</th>
            <
th>Product Group</th>
            <
th>Enabled</th>
            <
th>Current</th>
            <
th>Edit</th>
            <
th>Delete</th>
        </
tr>
        <?
php if(isset($products)){
        foreach(
$products as $product){ ?>
            <tr>
                <td class="center "><?php echo $product->id;?></td>
                <td class="center"><?php echo $product->name;?></td>
                <td class="center editable"><?php echo $product->fl_pcode;?></td>
                <td class="center editable"><?php echo $product->sq_pcode;?></td>
                <td class="center editable"><?php echo $product->pl_pcode;?></td>
                <td class="center"><?php echo $product->name;?></td>
                <td class="center"><?php echo $product->product_group;?></td>
                <td class="center">
                            <?php if($product->enabled==0):?>
                            <form method="link" action="<?php echo site_url('products/enable/'.$product->id);?>">
                                <input type="submit" class="redbutton" value="Disabled">
                            </form>    
                            <?php else:?>                
                            <form method="link" action="<?php echo site_url('products/disable/'.$product->id);?>">
                                <input type="submit" class="greenbutton" value="Enabled">
                            </form>    
                            <?php endif;?>
                </td>
                <td class="center">
                            <?php if($product->current==0):
                                    echo 
'Current';
                                elseif(
$product->current==1):                
                                    echo 
'Upcoming';
                                else:
                                    echo 
'Discontinued';
                             endif;
?>
                </td>
                <td class="center">
                    <a href="<?php echo site_url('products/edit/'.$product->id);?>" class="greenbutton" >Edit</a>   
                </td>  
                <td class="center">
                    <form method="link" action="<?php echo site_url('products/delete/'.$product->id);?>">
                        <input type="submit" class="redbutton yesno" value="Delete">
                    </form>
                </td>  
            </tr>
        <?php } }?>

    <?php echo $this->pagination->create_links();?>
</table> 
This is my model: 

PHP Code:
function getProducts()
    {
        
$this->db->select('products.*,categories.name AS cname');
        
$this->db->join('categories''products.category = categories.id');
        
//pagination


        
$this->db->limit(10);
        
$query $this->db->get('products');
        if(
$query->num_rows()>0){
            foreach(
$query->result() as $row){
                
$products[]=$row;
            }
            return 
$products;
        }
    } 
And this is my controller:

PHP Code:
class Products extends MX_Controller {

     
  public function __construct() {
 
       parent:: __construct();
 
        $this->load->library('pagination');
 
     
    
}



    function 
index($offset 0)
    {
        
        if( ! 
$this->bitauth->logged_in()||! $this->bitauth->has_role('admin') )
        {
            
$this->session->set_userdata('redir'current_url());
            
redirect('access/login');
        }
        
$data['header']=Modules::run('header/header/index'); 
        
        
$this->load->model('admin_products_model');
        
$data['products']= $this->admin_products_model->getProducts();    

        
//pagination
        

        
$config['base_url'] = base_url().'products/index/';
        
$config['total_rows']=$this->db->get('products')->num_rows();

        
$config['per_page']=10;
        
$config['num_links']=10;

        
$this->pagination->initialize($config);
        
$data['records']=$this->db->get('products',$config['per_page'],$offset);//this->uri->segment(3)
             
        
$this->load->view('products',$data);
    
    } 
In the attached preview the pagination doesn't work, I'm stuck with the first 10 products. Am I missing something?
View html source code in browser which generated by CI. pagination work, but not show because you insert it not in tr>td. Insert  

PHP Code:
<?php echo $this->pagination->create_links();?>

after </table> tag, or change to 

Code:
<tr><td colspan="11"> <?php echo $this->pagination->create_links();?></td></tr>
You missing $config['uri_segment']. Pagination library dont know what page you open and how to change url for other ling in paginator. set $config['uri_segment'] = $offset;