Welcome Guest, Not a member yet? Register   Sign In
[SOLVED]Custom Pagination...please help
#1

[eluser]Sarfaraz Momin[/eluser]
Hello,
Please help me with this pagination issue. First of all I do not get the prev link if I increase the numlinks to display and secondly can i change the number display in the uri segment e.g right now if i have 10 records per page it shows as 10 / 20 / 30 accordingly per page. can i make it 1 / 2 / 3. All CI gurus plz help.

No replies encouraged me to do this small helper class which works as i want. Thought might help someone. Not the best of the code but still works
Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
* Pagination helper.
* The one in CI simply doesn't work for me
*/
function pagination($url, $total, $perPage, $currentRecord)
{
    $maxPage = ceil($total / $perPage) - 1;
    $pageNum = $currentRecord;
    if(!$pageNum){
        $pageNum = 1;
    }
    $nav='';
    for($page = 1; $page <= $maxPage; $page++)
    {
        if ($page == $pageNum)
        {
            $nav .= "<span class=\"navbar-selected\">$page</span> "; // no need to create a link to current page
        }
        else
        {
            $nav .= "<span><a href=\"".$url."$page/\" class=\"navbar\">$page</a></span>";
        }
    }

    if ($pageNum > 1)
    {
        $page  = $pageNum - 1;
        $prev  = " <a href=\"".$url."$page/\" class=\"prevnext\">[Prev]</a> ";
    }
    else
    {
        $prev  = '&nbsp;'; // we're on page one, don't print previous link
    }

    if ($pageNum < $maxPage)
    {
        $page = $pageNum + 1;
        $next = " <a href=\"".$url."$page/\" class=\"prevnext\">[Next]</a> ";

    }
    else
    {
        $next = '&nbsp;'; // we're on the last page, don't print next link
        $last = '&nbsp;'; // nor the last page link
    }
    $link = $prev . $nav . $next;
    return $link;
}
?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB