emprit

paging

Mar 18th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. <?php
  2.  
  3. class paging {
  4.     private $lim;
  5.     private $now;
  6.     public function __construct()
  7.     {
  8.         $this->lim = 5;
  9.         $this->now = 0;
  10.     }
  11.     public function main($num,$url)
  12.     {
  13.         $jumlahpagging = ceil($num/$this->lim);
  14.         $re  = "<ul>";
  15.         $prev_dis = ($this->now - 1 <= 0) ? "disabled" : '';
  16.         $next_dis = ($this->now + 1 > $jumlahpagging) ? "disabled" : '';
  17.         $link_prev = ($this->now - 1 <= 0) ? $url.($this->now - 1) : '#';
  18.         $link_next = ($this->now + 1 <= 0) ? $url.($this->now - 1) : '#';
  19.         $re .= "<li class='$prev_dis'><a href='". $url.($this->now - 1) ."' disabled='$prev_dis'>Sebelumnya</a></li>";
  20.         $re .= "<li class='$next_dis'><a href='". $url.($this->now + 1) ."' $next_dis>Selanjutnya</a></li>";
  21.         $re .= "</ul>";
  22.         return $re;
  23.     }
  24.    
  25.     public function position($now,$lim)
  26.     {
  27.         $this->lim = $lim;
  28.         $this->now = ($now < 1) ? 0 : $now;
  29.         return ($this->now - 1) * $lim;
  30.     }
  31. }
  32. $paging = new paging();
  33. if(isset($_GET['p'])){
  34. $paging->position(intval($_GET['p']),10);
  35. echo "<div class='pagination'>".$paging->main(50,'?p=',intval($_GET['p']))."</div>";
  36. }
Advertisement
Add Comment
Please, Sign In to add comment