Welcome Guest, Not a member yet? Register   Sign In
CI pagination links problem
#1

[eluser]Kryptonian[/eluser]
Hello guys

Have you guys encountered this in Code Igniter pagination for example you have a list of records then if you clicked the pagination link like number 2 you will go the second page but if you check the pagination links.... the page number 2 is not in bold format. The bold format is still in the 1st page (number 1).



Here's the code:
Code:

<?php

// ------------------------------- my controller --------------------------------- //
function index($page = '0') {

$pagination_config['base_url'] = site_url() . 'settings/categories/index/';
$pagination_config['total_rows'] = $total;
$pagination_config['per_page'] = '5';
$pagination_config['full_tag_open'] = '<p>';
$pagination_config['full_tag_close'] = '</p>';
$this->pagination->initialize( $pagination_config );

echo $this->pagination->create_links();

}

// ------------------------------- my model --------------------------------- //
function __construct($page = 0) {
// call parent constructor
parent::Model();

$CI =& get_instance();
$CI->load->model( 'Database_model' );

$user_code = $this->session->userdata( 'user_code' );
$company_code = $this->session->userdata( 'company_code' );

$today = date("Y-m-d");
$tomorrow = date('Y-m-d', strtotime("+1 day, $today"));

$where =
"
`company_code` = '$company_code'
AND '$tomorrow' BETWEEN `valid_from` AND `valid_to`
";

$order_by = ' ORDER BY `category_id` ASC LIMIT '.$page.', 5';
$result = $CI->Database_model->select( 'DISTINCT *', CATEGORY, $where, $total, $order_by );

return $result;
}


?&gt;


Thanks in advance ;-)
#2

[eluser]Kryptonian[/eluser]
help anyone? please....
#3

[eluser]thunder uk[/eluser]
There seems to be a couple of gaps in the code above.

I can't see whether $page gets modified or not before it's being used in your LIMIT clause, which would perhaps be the first thing to check.

Incidentally, I'd try to use your "page" values starting from 1 rather than 0. In your model, you can set a limit variable like this.

Code:
$perpage = 5; // from your example
$limitArg = (int)($page * $perpage) - $perpage;

...

$order_by = ' ORDER BY `category_id` ASC LIMIT '.$limitArg.', '.$perpage;
#4

[eluser]marcoss[/eluser]
[quote author="marknt" date="1183115274"]
Code:
$pagination_['base_url'] = site_url() . 'settings/categories/index/'; ;
[/quote]

You are using a non-conventional uri structure, so you need to tell the system where to find the current page, you do that by adding this one line to your config.

Code:
$pagination_['uri_segment'] = 4; // settings/categories/index/#4

And next time, please use code tags.
#5

[eluser]KJTED[/eluser]
I had this problem also and the solution that Marcoss posted fixed it. So thank you for that Smile Sometimes I wish the codeigniter documentation files were a bit better and went into more detail with things like that.
#6

[eluser]marcoss[/eluser]
[quote author="KJTED" date="1189636096"]I had this problem also and the solution that Marcoss posted fixed it. So thank you for that Smile Sometimes I wish the codeigniter documentation files were a bit better and went into more detail with things like that.[/quote]

That information is currently on the User Guide, http://ellislab.com/codeigniter/user-gui...ation.html
Quote:$config['uri_segment'] = 3;

The pagination function automatically determines which segment of your URI contains the page number. If you need something different you can specify it.




Theme © iAndrew 2016 - Forum software by © MyBB