Subscribe to karimi's Blog        RSS Feed

karimi's Blog has no entries yet


Page 1 of 1

November 2014

S M T W T F S
      1
2345678
9101112131415
16171819202122
23 242526272829
30      

Tags

    Search My Blog

    0 user(s) viewing

    0 Guests
    0 member(s)
    0 anonymous member(s)

    Categories

    PHP Pagination

    class Pagination
    {
    var $page, $pages, $total, $max_links, $xtra;
    function _Construc()
    {

    }
    public function Print_pagination()
    {
    $pg=$this->page;
    $pages=$this->pages;
    $total=$this->total;
    //echo "pages=$pages ,total=$total";
    //if($total >= $pages) return;
    $max_pages_links=$this->max_links;
    $extra=$this->xtra;
    ?>
    <div id="paging">
    <table cellpadding="0" cellspacing="0" border="0" width="98%" align="center">
    <tr>
    <!-- <td><?php echo $start.' - '.$upto.' of '.$total.' results found'?></td>-->
    <td align="right">
    <?php echo 'Page '.$pg.' of '.$pages.'&nbsp;&nbsp; ';
    $cur_window_num = intval($pg / $max_pages_links);
    if ($pg % $max_pages_links) $cur_window_num++;

    $max_window_num = intval($pages / $max_pages_links);
    if ($pages % $max_pages_links) $max_window_num++;
    $extra_uri='';
    if(!empty($extra))
    {
    $extra_uri=$extra;
    }
    if($pg > 1)
    {
    $p=$pg-1;
    echo '<a class="page_bg" style="margin-right:3px;" href="'.$_SERVER['PHP_SELF'].'?pg='.$p.$extra_uri.'" >&laquo;</a>&nbsp;';
    }
    if ($cur_window_num > 1) {
    $p=($cur_window_num - 1) * $max_pages_links;
    echo '&nbsp;<a class="page_bg" href="'.$_SERVER['PHP_SELF'].'?pg='.$p.$extra_uri.'" >...</a>&nbsp;';
    }
    $check = 0;
    for ($jump_to_page = 1 + (($cur_window_num - 1) * $max_pages_links); ($jump_to_page <= ($cur_window_num * $max_pages_links)) && ($jump_to_page <= $pages); $jump_to_page++) {
    if ($jump_to_page == $pg) {
    echo '<a class="page_bg page_on">'.$jump_to_page.'</a>';
    } else{
    echo '&nbsp;<a class="page_bg" href="'.$_SERVER['PHP_SELF'].'?pg='.$jump_to_page.$extra_uri.'">' . $jump_to_page . '</a>&nbsp;';
    }
    $check++;
    }
    if ($cur_window_num < $max_window_num)
    {
    $p=(($cur_window_num) * $max_pages_links + 1);
    echo '&nbsp;<a class="page_bg" href="'.$_SERVER['PHP_SELF'].'?pg='.$p.$extra_uri.'" >...</a>&nbsp;';
    }
    if($pg < $pages && $pages !=1)
    {
    $p=$pg+1;
    echo '&nbsp;<a class="page_bg" href="'.$_SERVER['PHP_SELF'].'?pg='.$p.$extra_uri.'" >&raquo;</a>&nbsp;';
    }
    if($pages >=10 && $pg!=$pages)
    {
    $p=$pages;
    echo '&nbsp;<a class="page_bg" href="'.$_SERVER['PHP_SELF'].'?pg='.$p.$extra_uri.'" >Last</a>';
    }
    ?></td>
    </tr>
    </table>
    </div>
    <?php
    }
    }