I am new to Codeigniter. This is my first experience in Codeigniter. I have problem in pagination. I have tried lot of codes given on forums and blogs. Lastly I followed a tutorial, link: CodeIgniter from Scratch- Day 16 - Displaying & Sorting Tabular Data - Nettuts+
Here is my code:
user.php
public function index($offset=0)
{
$limit = 10;
$this->load->model('user_model');
$results = $this->user_model->get_all_users($limit,$offset);
$data['users'] = $results['rows'];
$data['num_results'] = $results['num_rows'];
$this->load->library('pagination');
$config = array();
$config['base_url'] = site_url('admin/user');
$config['total_rows'] = $data['num_results'];
$config['per_page'] = $limit;
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
$date['pagination'] = $this->pagination->create_links();
$data['page_title'] = "List Of Users";
$this->load->view('admin/users', $data);
}
user_model.php
function get_all_users($limit, $offset)
{
$q = $this->db
->select('user_id,user_email,login_name,phone_num,user_status')
->from('tbl_user')
->limit($limit,$offset);
$ret['rows'] = $q->get()->result();
$q = $this->db
->select('COUNT(*) as count', FALSE)
->from('tbl_user');
$tmp = $q->get()->result();
$ret['num_rows'] = $tmp[0]->count;
return $ret;
}
users.php
<?php
$this->load->view('includes/header');
$this->load->view('includes/menu-admin');
?>
<div id="container">
<?php if(isset($users)) { ?>
<p><?php $this->load->view('includes/footer'); ?></p>
<table id="users_table" class="board">
<tr>
<th class="blue-gradient">#</th>
<th class="blue-gradient">Email Address</th>
<th class="blue-gradient">Login Name</th>
<th class="blue-gradient">User Status</th>
<th class="blue-gradient">Current Status</th>
</tr>
<?php $count=1; ?>
<?php foreach ($users as $user) { ?>
<tr id="user_<?php echo $user->user_id; ?>" class="darker-on-hover">
<td><?php echo $count; ?></td>
<td><?php echo anchor('admin/profile/view/'.$user->user_id,$user->user_email , 'class="view-profile-details"'); ?></td>
<td><?php echo $user->login_name; ?></td>
<td><?php echo $user->user_status; ?></td>
<td>
<?php echo anchor('admin/user/edit/'.$user->user_id , '<img src="'.base_url().'images/edit.png" title="Edit User"/>'); ?>
<?php echo anchor('admin/user/remove/'.$user->user_id , '<img src="'.base_url().'images/remove.png" title="Remove User"/>', 'class="remove-user-event"'); ?>
</td>
</tr>
<?php $count++; } ?>
</table>
<?php } ?>
<div id="pageNum">
<?php if(strlen($pagination)): ?>
Pages: <?php echo $pagination; ?>
<?php endif; ?>
</div>
</div>
Please let me know if I am wrong?