need help in pagination

#1
[eluser]Kiran Dangol[/eluser]
Hi everybody,
I need help in pagination. I have gone through user_guide in order to take help using pagination library. I have autoloaded pagination library. Here given below are my full codes.

Code in Controller
Code:
<?php
//if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User extends CI_Controller {

function __construct()
    {
        parent::__construct();
                if(!($this->session->userdata('login_ok'))){
            redirect('home/index');
        }
    }

      
    function index(){
         redirect('user/user_log');        
    }
        
        function user_log(){
        $data['user_module_permission'] = user_module_permission();
        $data['user_permission'] = user_permission();
        $data['logtime']=$this->userprofile->user_log_time();
        
        //setting for pagination
        $pag_config['base_url'] = base_url() . '/user/user_log/';
        $pag_config['total_rows'] = count($data['logtime']['user_id']);
        $pag_config['per_page'] = 5;
        $pag_config['uri_segment'] = 3;
        $this->pagination->initialize($pag_config);
        $paginator=$this->pagination->create_links();
        $data['paginator']=$paginator;
        $this->load->view('user_management/main',$data);
    }    
    
}
?>

here is view page code
Code:
<table class="header_ul">
  <tr>
    <td class="header_top">SN</td>
    <td class="header_top">User Name</td>
    <td class="header_top">Full Name</td>
    <td class="header_top">Login Time</td>
    <td class="header_top">Logout Time</td>
    <td class="header_top">Ip Address</td>
  </tr>
  &lt;?php
  for ($i=0;$i<count($logtime['user_id']);$i++){
      $count=$i+1;
    echo "<tr>";
    echo "<td class='header_list'>".$count."</td>";
    echo "<td class='header_list'>".$logtime['user_name'][$i]."</td>";
    echo "<td class='header_list'>".$logtime['full_name'][$i]."</td>";
    echo "<td class='header_list'>".$logtime['login_time'][$i]."</td>";
    echo "<td class='header_list'>".$logtime['logout_time'][$i]."</td>";
    echo "<td class='header_list'>".$logtime['ipaddress'][$i]."</td>";
    echo "</tr>";
  }
  ?&gt;
  <tr>
  <td colspan="6" class='header_list'>&lt;?php echo $paginator; ?&gt;</td>
  </tr>
</table>

And the model code is given below
Code:
class Userprofile extends CI_Model{
    function __construct(){
      
    }
    function index(){
     parent::__construct();
    }
        
        function user_log_time(){
        $query=$this->db->query("select * from log_time order by id desc");
        $count=0;
        foreach($query->result() as $row){
            $data['user_id'][$count]=$row->user_id;
            $details=$this->details_of_user($row->user_id);
            $data['user_name'][$count]=$details['user_name'];
            $data['full_name'][$count]=$details['full_name'];
            $data['login_time'][$count]=$row->logintime;
            $data['logout_time'][$count]=$row->logouttime;
            $data['ipaddress'][$count]=$row->ipaddress;
            $count++;
        }
        return $data;
    }
    
}//End of Class
//End of Model user Profile
?&gt;

#2
[eluser]Atharva[/eluser]
You need to use SQL LIMIT in your user_log_time function query
Code:
function user_log_time($offset,$perpage){
        $query=$this->db->query("select * from log_time order by id desc LIMIT $offset,$perpage");
.
.
.
}

In your controller
Code:
$offset = $this->uri->segment(3,0);
$perpage = 5;
$data['logtime']=$this->userprofile->user_log_time($offset,$perpage);

#3
[eluser]InsiteFX[/eluser]
This can also be changed.
Code:
$paginator=$this->pagination->create_links();
$data['paginator']=$paginator;

// can be changed to this:
$data['paginator'] = $this->pagination->create_links();

InsiteFX


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.