Welcome Guest, Not a member yet? Register   Sign In
paniation help
#1

[eluser]Programming Life[/eluser]
Please tell me how i use pagination in short paging to get 20 records per page
what i have done is all shown below config , model , controller , n actuall page
all code is below
thanks if any help is replies


pagination.php config file
=======================
Code:
<?php
$config['base_url'] = 'http://localhost/working/CodeIgniter_1.6.3/index.php/Admin/users/';
$config['total_rows'] = '300';
$config['per_page'] = '20';
?>


controller 'Admin' have function
Code:
function users() {
    
        $data['userdata']    = $this->Madmin->getAllUsers();        
          
        $data['usersStatus'] = $this->Madmin->getAllUsersStatus();

        $data['title']='Users Lists';
        $data['heading']='Users List ';
        $this->load->view('admin/users',$data);
    
    }

view name is : users
====================
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo $title;?></title>
</head>

<body>
<?php    $data_ADD = array( 'src'  => 'asset/newobject.gif' ,'title'=>'Add User' , 'border' => '0');?>
<?php    $data1 = array( 'src'  => 'asset/non.gif' ,'title'=>'Delete User' , 'border' => '0');?>
<?php    $data_EDIT = array( 'src'  => 'asset/edit.gif', 'title'=>'Edit User' , 'border' => '0');?>

<?php echo $this->load->view('admin/header'); ?>

&lt;?php echo br().'<hr>'; ?&gt;
&lt;?php
echo anchor('User/register',img($data_ADD).'Add New'); echo br();
echo 'Total registered Users ::&nbsp; '.$this->db->count_all('register');
echo br();


if( empty($userdata) ) { //if no recored found
echo $msg = 'No Recored Found';

}else {
    
$this->table->add_row('<b>ID', '<b>NAME' , '<b>COUNTRY', '<b>EMAIL','<b>Status','<b>Actions');
//$this->table->add_row(  anchor('User/register',img($data_ADD)) );

$num=1;
$statusCount=0;
foreach($userdata as $records) {
        $color = ($num%2==0)? '#00CCCC': '#00CCCC';
echo '<p style=background-color:'.$color.'>';


    $status = ( $usersStatus[$statusCount]=='yes')? 'Active' :'InActive';
    $this->table->add_row( $records['id'] , $records['name'] , $records['country'] , $records['email'] , $status ,anchor('Admin/delete/'.$records['id'].'',img($data1)) , anchor('Admin/editUser/'.$records['id'],img($data_EDIT)) );            
    


echo '</p>';
$num++;
$statusCount++;
}
echo $this->table->generate();

}//if end

echo $this->pagination->create_links();
?&gt;
&lt;/body&gt;
&lt;/html&gt;


And the model i have is this => 'Madmin'
Code:
function getAllUsers() {
        $dbData = array();
          $this->db->select('*');
        $this->db->limit('');
        $query = $this->db->get('register');        
        
        foreach( $query->result_array() as $records ) {
          $dbData[] = $records;
        }
        return $dbData;
    }
    
    function getAllUsersStatus() {
        $dbData = array();
          $this->db->select('status');
        $query = $this->db->get('login');
        
        foreach( $query->result_array() as $records ) {
          $dbData[] = $records;
        }
        return $dbData;
    }
#2

[eluser]Chris Newton[/eluser]
Something like this:


Code:
// CONTROLLER
function users() {
    
    $this->load->library('pagination');
    $this->load->model('Madmin');


    $offset = $this->uri->segment(6); //whichever segment has the pagination data
    $data['userdata'] = $this->Madmin->get('20',$offset);  
    
    //$config['uri_segment'] = 6; // only needed if you're manually putting your pagination somewhere specific in the URI string.
    $config['base_url'] =  'http://localhost/working/CodeIgniter_1.6.3/index.php/Admin/users/';
    $config['total_rows'] = $this->db->count_all('register');
    $config['per_page'] = '20';
    // .... add other pagination config options.
    $this->pagination->initialize($config);

    $data['pagination'] =  $this->pagination->create_links();


    $data['title']='Users Lists';
    $data['heading']='Users List ';
    $this->load->view('admin/users',$data);
}

// IN THE VIEW, ADD THIS: echo $pagination;


// MODEL
function get($limit,$offset)
{
    $dbData = array();
    $this->db->select('*');
    $query = $this->db->get('register',$limit,$offset);

    foreach( $query->result_array() as $records )
    {
      $dbData[] = $records;
    }
    return $dbData;
}

Basically the pagination just formats and creates links with numbers added to the end. You need to take those numbers and pull the appropriate data from your database.




Theme © iAndrew 2016 - Forum software by © MyBB