ОБСУЖДЕНИЕ

Пагинация для БТ

2 сообщений0 просмотровОткрыта
#1
Класс пагинации для Битвы титанов

PHP
class pagination {
    private $page, $pages, $items, $items_per_page;
    public function __construct ($items,
                                 $items_per_page) {
        $this -> items          = $items;
        $this -> items_per_page = $items_per_page;        
        $this -> pages          = $this -> get_pages ();
        $this -> page           = intval ($_GET['page']);
        if ($this -> page < 1) {
            $this -> page = 1;
        }
        if ($this -> page > $this -> pages) {
            $this -> page = $this -> pages;
        }
    }
    public function get_pages () {
        return ceil ($this -> items / $this -> items_per_page);
    }
    public function display () {        
        if ($this -> page > 1) {
            $output .= "<a href='?page=1'>&lt;&lt;</a> ";
            $output .= "<a href='?page=" . ($this -> page - 1) . "'>&lt;</a> ";
        }
        for ($page = $this -> page - 2;
             $page<= $this -> page + 2;
             $page++) {            
            if ($page > 0 && $page <= $this -> pages) {
                if ($page == $this -> page) {
                    $output .= $page . " ";
                }
                else {
                    $output .= "<a href='?page=$page'>$page</a> ";
                }
            }
        }
        if ($this -> page + 1 <= $this -> pages) {
            $output .= " <a href='?page=" . ($this -> page + 1) . "'>&gt;</a>";
        }
        if ($this -> page != $this -> pages) {
            $output .= " <a href='?page=" . $this -> pages . "'>&gt;&gt;</a>";
        }
        
        return $output;
    }
}


Пример:

PHP
$pagination = new pagination (100, 10);
// ...
echo $pagination -> display ();
#2
а есть нормальный скипт типо бт или варворов??