Witam ma stronnicowanie ale cos nie do konca dziala
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 )
{
return ceil( $num / $this->ileMax ); }
/**
* 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' )
{
$link = str_replace( '>%<', '><b>'.( $i + 1 ).'</b><', $this->url ); }
else
{
$link = str_replace( '>%<', '>'.( $i + 1 ).'<', $this->url ); }
}
else
{
if( $mod == 'plus' )
{
$link = str_replace( '>%<', ' title="'.$this->text['T_NEXT'].'">'.$this-> text['NEXT'].'<', $this->url );
$link = str_replace( '%', ( $i * $this->ileMax ) + $this->ileMax, $link ); }
else if( $mod == 'minus' )
{
$link = str_replace( '>%<', ' title="'.$this->text['T_PREV'].'">'.$this-> text['PREV'].'<', $this->url );
$link = str_replace( '%', ( $i * $this->ileMax ) - $this->ileMax, $link ); }
}
return $link;
}
/**
* Dodawanie separatora
*
*/
function addSep()
{
$this->link .= $this->text['SEPAR'];
}
/**
* " (...) ze 100 "
*/
function addzIlu( $i )
{
$this->link .= str_replace( '%', $i, $this->text['ZILU'] ); $this->addSep();
}
}
?>
Kod:
include("klasa.php");
{
$p = $_GET['p'];
}
else
{
$p = 0;
}
$result = mysql_query("SELECT * FROM articles WHERE id_cat='$id' ORDER BY tytul ASC"); // 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 );
echo $pager->showPager();
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?