Klasa:
<?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 = 2; # ileMax na strone var $actPage; # aktualna strona var $ilePages; # ile stron (wynik pager::ileStron) var $pagerMax = 2; 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="cat.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' ) { text['NEXT'].'<', $this->url ); } else if( $mod == 'minus' ) { text['PREV'].'<', $this->url ); } } return $link; } /** * Dodawanie separatora * */ function addSep() { $this->link .= $this->text['SEPAR']; } /** * " (...) ze 100 " */ function addzIlu( $i ) { $this->addSep(); } } ?>
Kod:
include("klasa.php"); { $p = $_GET['p']; } else { $p = 0; } // i je wyświetlamy echo '<td><a href="art.php?id='.$row['id'].'"><b>'.stripslashes($row['tytul']).'</b></a></td><td align=right> <b>'.stripslashes($row['opis']).'</b></td>'; } $pager = new pager( $p, $num_rows );
I dziala ona na zasadzie ze: Mam 3 rekordy w bazie a chce zeby wyswietlala aby 2 i nastepna strona a skrypt robi:
Cytat
<< Poprzednia :: 1 2 z 2 stron :: Nastêpna >>
i niby dobrze ale na kazdej stronie wyswietla wszystkie rekordy z bazy. Co źle zrobiłem?