Kiedys napisalem sobie prosta klase do stronicowania wynikow z mysqla, moze sie przydac:
[php]<?php
class pager
{
/* przewijanie */
var $_home = '|<';
var $_prev = '<';
var $_next = '>';
var $_end = '>|';
/*classa linkow*/
var $_class = '';
/* wynikow na strone*/
var $_recordonpage = '10';
var $separator = '';
/* inne :] */
var $page_id = '1';
var $row_number;
var $page_number;
/* linki */
var $home_link;
var $prev_link;
var $links;
var $next_link;
var $end_link;
/*konstruktor*/
function pager($row_number, $page_id, $on_page='')
{
if($on_page!=='') $this->setRecordOnPage($on_page);
if(($row_number % $this->_recordonpage)!==0) {
$this->page_number = ($row_number / $this->_recordonpage) - (($row_number % $this->_recordonpage) / $this->_recordonpage) + 1; }
else {
$this->page_number = $row_number / $this->_recordonpage; }
$this->row_number = $row_number;
if($page_id > 0) $this->page_id = $page_id;
}
/*ustalanie wygladu przewijania*/
function setNav($home, $prev, $next, $end)
{
if($home!=='') $this->_home=$home;
if($prev!=='') $this->_prev=$prev;
if($next!=='') $this->_next=$next;
if($end!=='') $this->_end=$end;
}
/*clasa dla linkow*/
function setClass($class)
{
if($class!=='') $this->_class=$class;
}
/*ilosc wynikow na strone*/
function setRecordOnPage($on_page)
{
if($on_page!=='') $this->_recordonpage = $on_page;
}
/*ustalanie id stron*/
function nav()
{
$this->home_id = 1;
$this->next_id = $this->page_id+1;
$this->prev_id = $this->page_id-1;
$this->end_id = $this->page_number;
}
/*tworzenie klas dla linkow*/
function render_class()
{
if($this->_class!=='') {
$this->_class = ' class="'.$this->_class.'"'; }
else{
$this->_class='';}
}
/*wyglad linkow :]*/
function render_links($page_id, $name)
{
$link = '<span'.$this->_class.'><a href="?page_id='.$page_id.'">'.$name.'</a></span>'.$this->separator;
return $link;
}
/*home*/
function home()
{
if($this->page_id > 1) {
$this->home_link = $this->render_links($this->home_id, $this->_home); }
}
/*prev*/
function prev()
{
if($this->prev_id > 0) {
$this->prev_link = $this->render_links($this->prev_id, $this->_prev); }
}
/*generowanie linkow*/
function links()
{
/* gdy id jest rowne 1 */
if($this->page_id == '1') {
$page_id = 1;
while($page_id <= 3) {
if($page_id==$this->page_id) {
$this->links .= '<span'.$this->_class.'><strong>'.$page_id.'</strong></span>'.$this->separator; }
elseif($page_id <= $this->end_id) {
$this->links .= $this->render_links($page_id, $page_id); }
$page_id++;
}
if($page_id < $this->end_id) $this->links .= '...'.$this->separator;
return true;
}
/* gdy id jest rowne ostatniej stronie */
if($this->page_id == $this->end_id) {
$page_id = $this->end_id - 2;
if($page_id > 1) $this->links .= '...'.$this->separator;
$page_id_end = $this->end_id;
while($page_id <= $page_id_end) {
if($page_id==$this->page_id) {
$this->links .= '<span'.$this->_class.'><strong>'.$page_id.'</strong></span>'.$this->separator; }
elseif($page_id > 0){
$this->links .= $this->render_links($page_id, $page_id); }
$page_id++;
}
return true;
}
/*w innym wypadku :] */
else {
if($this->page_id >= 4) $this->links .= '...'.$this->separator;
$page_id = $this->page_id - 2;
$page_id_end = $this->page_id + 2;
while($page_id <= $page_id_end) {
if($page_id==$this->page_id) {
$this->links .= '<span'.$this->_class.'><strong>'.$page_id.'</strong></span>'.$this->separator; }
elseif($page_id > 0 && $page_id <= $this->page_number) {
$this->links .= $this->render_links($page_id, $page_id); }
$page_id++;
}
if($this->page_id <= ($this->page_number - 3)) $this->links .= '...'.$this->separator;
return true;
}
}
/*next*/
function next()
{
if($this->next_id <= $this->page_number) {
$this->next_link = $this->render_links($this->next_id, $this->_next); }
}
/*end*/
function end()
{
if($this->page_id < $this->end_id) {
$this->end_link = $this->render_links($this->end_id, $this->_end); }
}
/*tworzenie pagera*/
function render()
{
echo '<div class="pager">';
$this->render_class();
$this->nav();
$this->home();
echo $this->home_link;
$this->prev();
echo $this->prev_link;
$this->links();
echo $this->links;
$this->next();
echo $this->next_link;
$this->end();
echo $this->end_link;
echo '</div>';
}
/*limit*/
function limit()
{
$limit_min = ($this->_recordonpage * ($this->page_id - 1));
return $limit_min;
}
/*wyswietlanie ilosci wynikow na strone*/
function onPage()
{
return $this->_recordonpage;
}
}
/* Przyklad uzycia */
$row_number = $db -> row_number('katalog'); //pobranie ilosci wierszy w tabeli, tutaj zmienic
$pager=new pager($row_number, $_GET['page_id']); //stworzenie pagera
$pager -> setClass('nawigacja'); //nadanie nazwy klasy dla pagera
$query='SELECT * FROM katalog LIMIT '.$pager -> limit().', '.$pager -> onPage(); //zapytanie dal ktorego przeznaczony jest pager
$result = $db -> query($query); //tutaj zmienic
while($row = mysql_fetch_array($result))
{
echo $row['title']; //tutaj daj co chcesz, czyli wyswielanie wynikow z mysqla

echo '<br />';
}
$pager -> render(); // wyswietlenie nawygacji pagera
?>[/php]
Przyklad uzycia jest oparty na klasie do obslugi bazy danych wiec trzeba pozmieniac na "swoje"

Wyswietla ladna nawigacje, mozna ustalic ilosc wynikow na strone, klase dla linkow w nawigacji, sam jej wyglad.