А я бы такую зафигарил
class PAGINGS{
public $total;
private $total_pages;
private $page;
private $start;
private $end;
public $get;
public $count_get;
public function __construct($size, $query){
$this->total = mysql_result(mysql_query(preg_replace('~SELECT (.*?) FROM~isU', 'SELECT COUNT(*) FROM', $query).' ;'), 0);
$this->total_pages = ceil($this->total / $size);
$this->page = isset($_POST['page']) ? $_POST['page'] : $_GET['page'];
$this->page = !empty($this->page) && ctype_digit($this->page) && $this->page >= 1 && $this->page <= $this->total_pages ? $this->page : 1;
$this->start = ($this->page * $size) - $size;
$this->end = $this->start + $size < $this->total ? $this->start + $size : $this->total;
$this->get = mysql_query($query.' LIMIT '.$this->start.', '.$size.' ;');
$this->count_get = mysql_num_rows($this->get);
}
public function Links($link){
$link_list = '';
$start = $this->page - 3;
$end = $this->page + 3;
for($i = $start; $i <= $end; $i++){$link_list .= ($i <= $this->total_pages && $i >= 1 ? ($this->page != $i ? ' <a href="'.$link.'page='.$i.'&'.SID.'">'.$i.'</a> ' : ' ('.$i.') ') : '');}
return '<div class="nav">
'.($this->page > 1 ? '<a href="'.$link.'page='.($this->page - 1).'&'.SID.'"><<Пред. </a>' : '<<Пред. ').' | '.($this->page < $this->total_pages ? '<a href="'.$link.'page='.($this->page + 1).'&'.SID.'"> След.>></a>' : ' След.>>').'<br />
Стр.: '.($start > 1 ? '<a href="'.$link.'page=1&'.SID.'">1</a> ... ' : '').$link_list.($end < $this->total_pages ? ' ... <a href="'.$link.'page='.$this->total_pages.'&'.SID.'">'.$this->total_pages.'</a>' : '').'
<form action="'.$link.SID.'" method="post">
<p>
К стр.: <input class="form" name="page" maxlength="3" size="5" value="'.$this->page.'" />
<input class="submit" type="submit" value="Go" />
</p>
</form>
Показано с '.($this->start + 1).' по '.$this->end.' из '.$this->total.'
</div>'."\r\n";
}
//Пример
$PAGINGS = new PAGINGS(10, 'SELECT * FROM `test`'); // создание обьекта,1 аргумент пунктов на страницу,второй запрос к базе (без ; в конце)
if($PAGINGS->count_get > 0){
while($row = mysql_fetch_array($PAGINGS->get))
{
echo $row['bla'];
}
echo $PAGINGS->Links('?'); // вывод меню навигации в аргументе указывать адрес страницы
}