Russian English
jQuery Plugins & Javascript Functions
PHP Classes & Functions
HTML && CSS Frameworks

PHP class Pages

Опубликовано: 30.06.2016

Скачать PHP class Pages последнюю версию

Pages — распределитель на страницы.

Для работы требуется Smarty.

pages.php
<?php
/*!
 Pages 1.0.0
 https://skidanov.ru/dev/php-classes/pages/
 https://github.com/skidanovdima/pages
*/

class Pages {
    var $records;
    var $records_per_page;
    var $current_page;
    var $setup = array();

    private function setup() {
        $this->setup['first'] = 1;
        $this->setup['current'] = $this->current_page;
        $this->setup['last'] = ceil($this->records / $this->records_per_page);
        if ($this->current_page - 1 >= 1) {
            $this->setup['prev'] = $this->current_page - 1;
        }
        if ($this->current_page + 1 <= $this->setup['last']) {
            $this->setup['next'] = $this->current_page + 1;
        }
        $this->setup['list'] = array();
        for ($i = 1; $i <= $this->setup['last']; $i++) {
            $this->setup['list'][] = $i;
        }
    }

    public function __construct($records, $records_per_page, $current_page) {
        $this->records = $records;
        $this->records_per_page = $records_per_page;
        $this->current_page = $current_page;

        $this->setup();
    }
}

?>

Примеры

example.js
<?php
include('pages.php');

@mysql_connect('localhost', 'root', '7654321');
mysql_select_db('philosofiya.ru');

$result = mysql_query('SELECT COUNT(*) FROM `articles`');
$t_articles = mysql_fetch_assoc($result);
if (!isset($_GET['page'])) $_GET['page'] = 5;

$pages_articles = new Pages($t_articles['COUNT(*)'], 10, $_GET['page']);

$smarty->assign('pages', $pages_articles->setup);
echo preg_replace('%\>\s+\<%', '><', $smarty->fetch($_SERVER['DOCUMENT_ROOT'].'/sources/php-classes/pages/pages.tpl'));
?>

Демо

default default.min.css