Welcome Guest, Not a member yet? Register   Sign In
Codeigniter pagination
#11

[eluser]khagendra[/eluser]
Here is Your code
Code:
$pagination_config['base_url'] = base_url().'index.php/quotes/showchapter/'.$chapter_id.'/';
$pagination_config['total_rows'] = $query->num_rows();
$pagination_config['per_page'] = QUOTES_PER_PAGE;
$pagination_config['num_links'] = 2;
$pagination_config['first_link'] = 'Start';
$pagination_config['last_link'] = 'End';
$pagination_config['next_link'] = ' > ';
$pagination_config['prev_link'] = ' < ';
$pagination_config['uri_segment'] = 2;
$this->pagination->initialize($pagination_config);

-- I think u need to do some changes
1. Load the library pagination in ur controller(u can load in constructor function)

Code:
$this->load->library('pagination');

2. Where u have written the Query in ur code
Code:
$pagination_config['total_rows'] = $query->num_rows(); // $query ???

3. According to ur $pagination_config['base_url'] = base_url().'index.php/quotes/showchapter/'.$chapter_id.'/';, I think uri_segment should be 4
Code:
$pagination_config['uri_segment'] = 4;

4. Have u retrieved the list of data from any table with limit and offset valu, here is one line of code that u can write before $this->pagination->initialize($pagination_config); like this
Code:
$data['data_list'] = $this->model_name->function_name($config['per_page'],$this->uri->segment(4));
$this->pagination->initialize($pagination_config);

5. Here is the model function name example
Code:
function function_name($limit, $offset)
{
...ur codes
  $query = $this->db->get('tblname', $limit, $offset);
  $data=$query->result();
  $query->free_result();
  return $data;
}

6.last thing, u should have to write this line in ur view file to show links
Code:
echo $this->pagination->create_links();

Hope this will help you
#12

[eluser]RomanN[/eluser]
No, with 6 didn't work too.

Look, the url segment is changed correctly. I was on the 1-st page and my url was next:
Quote:http://localhost/quotes/index.php/quotes...hapter/1/0
Then I shifted to second page, data changed, the url became:
Quote:http://localhost/quotes/index.php/quotes...hapter/1/1

Seems correct, the last number was incremented, but url links represent first page as active.
#13

[eluser]RomanN[/eluser]
[quote author="khagendra" date="1256663293"]Here is Your code
Code:
$pagination_config['base_url'] = base_url().'index.php/quotes/showchapter/'.$chapter_id.'/';
$pagination_config['total_rows'] = $query->num_rows();
$pagination_config['per_page'] = QUOTES_PER_PAGE;
$pagination_config['num_links'] = 2;
$pagination_config['first_link'] = 'Start';
$pagination_config['last_link'] = 'End';
$pagination_config['next_link'] = ' > ';
$pagination_config['prev_link'] = ' < ';
$pagination_config['uri_segment'] = 2;
$this->pagination->initialize($pagination_config);

-- I think u need to do some changes
1. Load the library pagination in ur controller(u can load in constructor function)

Code:
$this->load->library('pagination');

2. Where u have written the Query in ur code
Code:
$pagination_config['total_rows'] = $query->num_rows(); // $query ???

3. According to ur $pagination_config['base_url'] = base_url().'index.php/quotes/showchapter/'.$chapter_id.'/';, I think uri_segment should be 4
Code:
$pagination_config['uri_segment'] = 4;

4. Have u retrieved the list of data from any table with limit and offset valu, here is one line of code that u can write before $this->pagination->initialize($pagination_config); like this
Code:
$data['data_list'] = $this->model_name->function_name($config['per_page'],$this->uri->segment(4));
$this->pagination->initialize($pagination_config);

5. Here is the model function name example
Code:
function function_name($limit, $offset)
{
...ur codes
  $query = $this->db->get('tbl_gallery', $limit, $offset);
  $data=$query->result();
  $query->free_result();
  return $data;
}

6.last thing, u should have to write this line in ur view file to show links
Code:
echo $this->pagination->create_links();

Hope this will help you[/quote]

Man, of course I've loaded library, wrote db query and created pagination links. I showed only the part of code. And as I've already said pagination works well in other method.

But, you really helped me!!!
when I changed
Code:
$pagination_config['uri_segment'] = 4;
everything started working correctly.

Thank you all, people.
#14

[eluser]ericrjones1[/eluser]
The third (3) uri_segment is set as the default uri_segment parameter of CI_Pagination class. So to have your pagination work correctly you need to set the uri_segment parameter to the dynamic pagination uri_segment

Code:
$config['uri_segment'] = 4

but also make sure that you are using the same uri_segment as part of your query offset

Code:
$data['foo'] = $this->foo_model->get_bar($config['per_page'], $this->uri->segment(4));

but just to make sure that you are cleaning and appropriately handling the incoming data from $this->uri->segment(4) because that is basically a $_GET variable
#15

[eluser]RomanN[/eluser]
Thank you. But all is clear now.




Theme © iAndrew 2016 - Forum software by © MyBB