Jump to content

How to use this Google style pagination function?


AdRock

Recommended Posts

I have found a nice function that displays pagination links like Google but have no idea how to use it with the MySQL query

I know how to connect to the database and create the query and display the query but how do i use the query with the function?  Do i need to use CEIL to get the number of pages?

Any help would be appreciated  ;D

I got the function from [url=http://cms.227net.com/php/google_like_pagination]http://cms.227net.com/php/google_like_pagination[/url]

[code]<?php
// quickLink
# writes out page links
function quickLink ($linkHref, $desc, $accessKey, $linkTitle) {
  $theLink = '<a href="'. $linkHref .'#pagination" title="'. $desc .'" accesskey="'.
                  $accessKey .'">'. $linkTitle .'</a>';
  return $theLink;

}
// google_like_pagination.php
function pagination($number, $show, $showing, $firstlink, $baselink, $seperator) {
    $disp = floor($show / 2);
    if ( $showing <= $disp) :

        if ( ($disp - $showing) > 0 ):
        $low  = ($disp - $showing);
        else:
        $low = 1;
        endif;
        $high = ($low + $show) - 1;

    elseif ( ($showing + $disp) > $number) :

        $high = $number;
        $low = ($number - $show) + 1;

    else:

        $low  = ($showing - $disp);
        $high = ($showing + $disp);

    endif;
   
    // next / prev / first / last
    if ( ($showing - 1) > 0 ) :
        if ( ($showing - 1) == 1 ):
        $prev  = quickLink ($firstlink, 'Previous', '', 'Previous');
        else:
        $prev  = quickLink ($baselink . $seperator . ($showing - 1),
        'Previous', 'z', 'Previous');
        endif;
    else:
        $prev  = 'Previous';
    endif;

    $next  = ($showing + 1) <= $number ?
    quickLink ($baselink . $seperator . ($showing + 1),
    'Next', 'x', 'Next') : 'Next';   

    if ( $_SERVER['REQUEST_URI'] == $firstlink ):
    $first = '<span class="sel">First Page</span>';   
    else:
    $first = quickLink ($firstlink, 'First Page', '', 'First Page');
    endif;   
   
    if ( $showing == $number ):
    $last = '<span class="sel">Last Page</span>';   
    else:
    $last = quickLink ($baselink . $seperator . $number, 'Last Page', '', 'Last Page');
    endif;
   
   
    $navi = '<div id="pagination">
    <ul>'."\n";
    // start the navi

        $navi .= '<li>'. $prev ."</li>\n";
   
    // loop through the numbers

    foreach (range($low, $high) as $newnumber):

          $link = ( $newnumber == 1 ) ? $firstlink :
                $baselink . $seperator . $newnumber;
          if ($newnumber > $number):
        $navi .= '';
        elseif ($newnumber == 0):
        $navi .= '';
        else:
        $navi .= ( $newnumber == $showing ) ?
            '<li class="sel">'. $newnumber .'</li>'."\n" :
            '<li>'. quickLink ($link, 'Page '. $newnumber, '', $newnumber) ."</li>\n";
        endif;                 
    endforeach;   
   
    // end the navi first line
   
        $navi .= '<li>'. $next ."</li>\n";
           
    $navi .= '</ul>'."\n";
    // second line
    $navi .= '<p>'. $first ."\n | Showing page ". $showing .' of '. $number ."\n | ".
            $last .'</p>
    </div>';
   
    return $navi;       

}
/*
## fake content example
               
foreach (range(1, 301) as $newnumber):
## fake content example
$content []=  'this is page '. ($newnumber - 1);
endforeach;
               
## Settings
               
$showing  = !isset($_GET["view"]) ? 1 : $_GET["view"];

    $firstlink = $_SERVER['PHP_SELF'];
    $seperator = '?view=';


## $baselink can be used if for example when the main script was index.php not the filename
    $baselink  = $firstlink;
   
## $show must be an odd number for this to work correctly
## This is the number of links between next and previous links
    $show = 3;

echo $content[$showing];
echo pagination(count($content), $show, $showing, $firstlink, $baselink, $seperator);               
*/
?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.