19 September, 2010

Get current page from Codeigniter pagination

Once i had a simple problem to get current page number from codeigniter pagination. After some checks, i managed to get it working by simple one line of code. I hope this will help someone like me.

//here: $this->uri->segment(n) is the segment value that you pass when initializing pagination
//and $config['per_page'] is number of pages to be displayed during pagination initialization in codeigniter
$currentPage = floor(($this->uri->segment(n)/$config['per_page']) + 1);
echo "Current Page:".$currentPage;

3 comments:

Anonymous said...

Hi great tip it works for me thanks for Posting. Get current page from Codeigniter pagination.

Anonymous said...

Just want to thank you for sharing this. Saved me a LOT of time. Best wishes!

sj said...

thanks buddy :)