

<?php /** * Klasa pagera * * @author Krzysztof 'Balon' Jagiełło < balonyo@gmail.com > * * ( pager::text['separ'] - separator odzdzielajacy linki do stron ) * ( pager::url - sposob wyswietlania urli ) * */ class pager { var $ileMax = 10; # ileMax na strone var $actPage; # aktualna strona var $ilePages; # ile stron (wynik pager::ileStron) var $pagerMax = 3; var $text = array( 'PREV' => '<< Poprzednia ::', 'NEXT' => ':: Następna >>', 'T_PREV' => 'Poprzednia strona', 'T_NEXT' => 'Następna strona', 'SEPAR' => ' ', 'ZILU' => 'z % stron' ); var $url = '<a href="linki.php?p=%">%</a>'; var $link; /** * Konstruktor klasy * * @param integer $actPage aktualny numer strony */ function pager( $actPage, $num, $limit = 10 ) { $this->actPage = $actPage; $this->ilePages = $this->ileStron( $num ); $this->ileMax = $limit; } /** * Pager * */ function showPager() { $this->prev(); $this->addSep(); for( $i = ( $this->actPage / $this->ileMax ) - $this->pagerMax; $i <= ( $this->actPage / $this->ileMax ) + $this->pagerMax; $i++ ) { if( $i >= 0 && $i < $this->ilePages ) { $this->page( $i ); $this->addSep(); } } $this->addzIlu( $this->ilePages ); $this->next(); return $this->link; } /** * Poprzednia strona * */ { if( ( $this->actPage / $this->ileMax ) == 0 ) { $this->link = $this->text['PREV']; } else { $this->link = $this->url( $this->actPage / $this->ileMax, '', 'minus' ); } } /** * Nastepna strona * */ { if( $this->actPage < ( ( $this->ilePages * $this->ileMax ) - $this->ileMax ) ) { $this->link .= $this->url( $this->actPage / $this->ileMax, '', 'plus' ); } else { $this->link .= $this->text['NEXT']; } } /** * wyswietlanie linku do strony * * @param integer $i numer strony */ function page( $i ) { if( $this->actPage == $i * $this->ileMax ) { $this->link .= $this->url( $i , 't' ); } else { $this->link .= $this->url( $i ); } } /** * Obliczanie ilosci stron * * @param integer $num liczba wpisow(mysql_num_rows) * @return $ilePages */ function ileStron( $num ) { } /** * Tworzenie urli, do $this->link podajemy juz <a href="(...) * a miejsce na numer strony oznaczamy jako % * * @param integer $i * @param string $bold * @return $link */ function url( $i, $bold = null, $mod = null ) { if( $mod == null ) { if( $bold == 't' ) { } else { } } else { if( $mod == 'plus' ) { $link = str_replace( '>%<', ' title="'.$this->text['T_NEXT'].'">'.$this->text['NEXT'].'<', $this->url ); } else if( $mod == 'minus' ) { $link = str_replace( '>%<', ' title="'.$this->text['T_PREV'].'">'.$this->text['PREV'].'<', $this->url ); } } return $link; } /** * Dodawanie separatora * */ function addSep() { $this->link .= $this->text['SEPAR']; } /** * " (...) ze 100 " */ function addzIlu( $i ) { $this->addSep(); } } ?>
Przyklad uzycia
<?php { $p = $_GET['p']; } else { $p = 0; } $sql->sql_query( 'SELECT id FROM LINKS WHERE zatw = "tak"' ); $num = $sql->sql_num_rows(); $pager = new pager( $p, $num ); ?>
pozdrawiam
ZEZWALAM NA WSZELKI UZYTEK wiem ze klasa porazkowa, ale to byla klasa na poczatku mojej przygody z php. teraz napisze cos lepszego
