Advertisement
GWibisono

helper halaman

May 4th, 2012
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.69 KB | None | 0 0
  1. <?php
  2.  
  3. if ( ! function_exists('myPage') )
  4. {
  5.     function myPage($num,$link)
  6.     {
  7. /*
  8. NUM adalah total halaman yang akan muncul
  9.  
  10. */ 
  11.         $aPage=array($num=>1);
  12.         $pos= intval($this->uri->segment(3)) ;
  13.         if($pos==0){
  14.             $pos==1;
  15.             $aPage[1]=1;
  16.         }
  17.        
  18.         //page sebelumnya
  19.         for($i=1;$i<=5;$i++)
  20.         {
  21.             $pos2=$pos-$i;
  22.             if($pos2<0) break;
  23.             $aPage[$pos2]=1;
  24.         }
  25.        
  26.         //page sesudahnya
  27.         for($i=1;$i<=5;$i++)
  28.         {
  29.             $pos2=$pos+$i;
  30.             if($pos2>$num) break;
  31.             $aPage[$pos2]=1;
  32.         }
  33.        
  34.         $s="<a href='link'>First</a>...";
  35.         ksort($aPage);
  36.         foreach($aPage as $id=>$val)
  37.         {
  38.             $s.="<a href='link/$id'>$id</a> ";
  39.         }
  40.         $s.="<a href='link/$num'>Last</a>...";
  41.         return $s;
  42.     }
  43.  
  44. }
  45. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement