Welcome Guest, Not a member yet? Register   Sign In
Pagination not setting active page?
#1

[eluser]Unknown[/eluser]
I have pagination, which seems to be functioning and doing increments correctly, however, I notice that the pagination links don't correctly set the active state, so that I can style it properly with CSS.

This is my code:

Code:
<?php
// Adjust config so we can use caching (without query string links)
$this->config->set_item('enable_query_strings',FALSE);

// Setup pagination            
$data['base'] = $this->config->item('base_url');
$data['per_pg'] = 3;

// Account for when $offset is not set
if ($this->uri->segment(4)) {
  $data['offset'] = $this->uri->segment(4);
}else{
  $data['offset'] = 0;
}

// Call the pagination library
$this->load->library('pagination');

$config['base_url'] = $data['base'] . '/manage/videos/page/';
$config['total_rows'] = $this->db->get('my_table')->num_rows();
$config['per_page'] = $data['per_pg'];
$config['cur_tag_open'] = '<span class="active">';
$config['cur_tag_close'] = '</span>';
$config['full_tag_open'] = '<div class="pagination right">';
$config['full_tag_close'] = '</div>';

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

// Get records to display
$sql = '
  SELECT id, video_url
  FROM `my_table`
  ORDER BY id DESC
  LIMIT ' . $data['offset'] . ', ' . $data['per_pg'] . '
  ';
$query = $this->db->query($sql);
$data['video_submissions'] = $query->result_array();

// Get the views
$this->load->view('admin/global/header');
$this->load->view('admin/global/navigation');
$this->load->view('admin/videos/default', $data);
$this->load->view('admin/global/footer');
?&gt;

This is the output:

Code:
<div class="pagination right">
<span class="active">1</span>&nbsp;
<a href="http://localhost/manage/videos/page/3">2</a>&nbsp;
<a href="http://localhost/manage/videos/page/6">3</a>&nbsp;
<a href="http://localhost/manage/videos/page/3">&gt;</a>&nbsp;&nbsp;
<a href="http://localhost/manage/videos/page/12">Last &rsaquo;</a>
</div>

The page I'm currently on to grab the above HTML from view source:

Code:
http://localhost/manage/videos/page/3

The problem?

First, I would expect that it would number the pages like 1, 2, 3, etc. That's besides the point, and more of an aesthetics issue. Right now, it's a nice to have.

Second, notice that I'm on the third page, but it still has page 1 marked as active. This happens no matter which page I choose. It's always showing the correct query results, but never showing a different active link then #1.

Is this a bug or just me being stupid with something? It happens Smile




Theme © iAndrew 2016 - Forum software by © MyBB