пример использования
$pg=page::pg_num('8', 'tabla');
$$mysqli->query("SELECT * FROM `tabla` LIMIT $pg['start'], $pg['num']"
while($res=$query->fetch_assoc())
{
echo 'тут выводим';
}
page::pg_str('?', $pg['page'], $pg['total']);
<?php
class page
{
public $num;
public $page;
public $posts;
public $post;
public $total;
public static function pg_num ($nm, $tb)
{
global $mysqli;
$num = $nm;
$page = $GLOBALS['_GET']['page'];
$post = $mysqli->query("SELECT COUNT(*) FROM $tb")->fetch_row();
$posts=$post['0'];
$total = intval(($posts - 1) / $num) + 1;
$page = intval($page);
if(empty($page) or $page < 0) $page = 1;
if($page > $total) $page = $total;
$start = $page * $num - $num;
return array("num" => $num, "page" => $page, "total" => $total, "start" => $start);
}
/* End function pg_num */
public static function pg_str($url, $page, $total)
{
if ($page != 1){$pervpage = '<a class="page_a" href='.$url.'page=1> В Начало </a><a class="page_a" href='.$url.'page='. ($page - 1) .'> Назад </a>';}
if ($page != $total){$nextpage = '<a class="page_a" href='.$url.'page='. ($page + 1) .'> Вперёд </a><a class="page_a" href='.$url.'page=' .$total. '> В Конец </a>';}
if($page - 2 > 0) $page2left = ' <a class="page_a" href='.$url.'page='. ($page - 2) .'>'. ($page - 2) .'</a>';
if($page - 1 > 0) $page1left = '<a class="page_a" href='.$url.'page='. ($page - 1) .'>'. ($page - 1) .'</a>';
if($page + 2 <= $total) $page2right = '<a class="page_a" href='.$url.'page='. ($page + 2) .'>'. ($page + 2) .'</a>';
if($page + 1 <= $total) $page1right = '<a class="page_a" href='.$url.'page='. ($page + 1) .'>'. ($page + 1) .'</a>';
echo '<div class="menu">'.$pervpage.$page2left.$page1left.'<span class="page_b">'.$page.'</span>'.$page1right.$page2right.$nextpage.'</div>';
}
/* End function pg_num */
}
/* end class page */
?>