$count = $db->query("SELECT `id` FROM `b`"->num_rows;
$n = new pager($count, '/index.php?page=');
$sql = $db->query('SELECT * FROM `b` ORDER BY `id` DESC LIMIT '.$n->start.','.$n->end);
while()...
echo $n->pag();
class pager
{
public $start;
public $end;
public $pages;
public $page;
public $count;
public $url;
function __construct($count, $url)
{
$this->page = abs(intval($_REQUEST['page']));
$this->count = $count;
$this->url = $url;
$this->pages = intval($this->count / 10)+1;
if(empty($this->page) || $this->page < 0)$this->page = 1;
if($this->page > $this->pages) $this->page = $this->pages;
$this->start = $this->page * 10 - 10;
$this->end = 10;
}
function pag ()
{
if($this->pages > 1){
$bp = $this->page - 1;
$np = $this->page + 1;
$bp2 = $this->page - 2;
$np2 = $this->page + 2;
$page = '<span class="s">'.$this->page.'</span>';
echo '<div class="nav"><center>';
// Условия для вывода ссылок
if($this->page > 1){
$back = '<span class="n"><a href="'.$this->url.$bp.'">'.$bp.'</a></span> ';
$last = '<span class="n"><a href="'.$this->url.$bp.'">« Назад</a></span> ';
}
if($this->page < $this->pages){
$next = ' <span class="n"><a href="'.$this->url.$np.'">'.$np.'</a></span>';
$new = ' <span class="n"><a href="'.$this->url.$np.'">Далее »</a></span>';
}
// Условия для вывода навигации и формы
if($bp2 >= 1)$back2 = '<span class="n"><a href="'.$this->url.$bp2.'">'.$bp2.'</a></span> ';
if($np2 <= $this->pages)$next2 = ' <span class="n"><a href="'.$this->url.$np2.'">'.$np2.'</a></span>';
if($bp2 > 1)$st_l = '<span class="n"><a href="'.$this->url.'1">«1</a></span> ';
if($np2 < $this->pages)$nx_l = ' <span class="n"><a href="'.$this->url.$this->pages.'">'.$this->pages.'»</a></span>';
//
if($this->pages > 10)$form = '<br/><form action="'.$this->url.'" method="post"><input type="text" name="page" size="5"><input type="submit" value="Go"/></form>';
echo $last.$new.'<br/>'.$st_l.$back2.$back.$page.$next.$next2.$nx_l.$form;
echo '</center></div>';
}
}
}