Понятная Человеческая Пагинация
Основа:
class pagination {
public $page, $pages, $of;
function __construct($c, $per) {
if (isset ($_GET['page'])) {
$this->page = (int) abs($_GET['page']);
if ($this->page == 0) $this->page = 1;
}
else {
$this->page = 1;
}
$this->pages = ceil($c/$per);
if ($this->page>$this->pages) $this->page = $this->pages;
$this->of = $per * $this->page - $per;
}
function output($ref) {
if (($this->page-1)!=0) $output .= ' <a href="' . $ref . 'page=' . ($this->page-1) . '">' . ($this->page-1) . '</a> | ';
$output .= $this->page;
if (($this->page+1)<=$this->pages) $output .= ' | <a href="' . $ref . 'page=' . ($this->page+1) . '">' . ($this->page+1) . '</a>';
return $output;
}
}
Пример:
$c = mysql_num_rows(mysql_query('SELECT * FROM `table`')); // кол-во записей из таблицы
if ($c!=0) {
$per = N; // записей на страницу
$pagination = new pagination ($c, $per);
$query = mysql_query(sprintf('SELECT * FROM `table` LIMIT %d, %d', $pagination->of, $per));
while ($result = mysql_fetch_array($query)) {
...
}
$pagination->output('?');
}
else {
...
}