I am new to programming. Please tell me how you can set the condition for displaying page-by-page navigation so that the first 15 link pages are displayed, then the last three and the last 10. When you click on 15, 16, etc. will be displayed. Thank.

button.class.php

<?php class Button { public $page; public $text; public $isActive; public function __construct($page, $isActive = true, $text = null) { $this->page = $page; $this->text = is_null($text) ? $page : $text; $this->isActive = $isActive; } public function activate() { $this->isActive = true; } public function deactivate() { $this->isActive = false; } } 

pagination.class.php

 class Pagination { public $buttons = array() public function __construct(Array $options = array('itemsCount' => 257, 'itemsPerPage' => 10, 'currentPage' => 1)) { extract($options); if (!$currentPage) { return; } /** @var int $pagesCount * @var int $itemsCount * @var int $itemsPerPage */ $pagesCount = ceil($itemsCount / $itemsPerPage); if ($pagesCount == 1) { return; } /** @var int $currentPage */ if ($currentPage > $pagesCount) { $currentPage = $pagesCount; } $this->buttons[] = new Button($currentPage - 1, $currentPage > 1, 'Previous'); for ($i = 1; $i <= $pagesCount; $i++) { if ($i > 15) { break; } $active = $currentPage != $i; $this->buttons[] = new Button($i, $active); } $this->buttons[] = new Button($currentPage + 1, $currentPage < $pagesCount, 'Next'); } } 

index.php

 <?php $page = isset($_GET['page']) ? (int)$_GET['page'] : 1; $p = new Pagination(array( 'itemsCount' => $data['count'][0]['cnt'], 'itemsPerPage' => 10, 'currentPage' => $page )); ?> <div align="center"> <?php foreach ($p->buttons as $button) : if ($button->isActive) : ?> <a href = '?page=<?=$button->page?>'><?=$button->text?></a> <?php else : ?> <span style="color:#555555"><?=$button->text?></span> <?php endif; endforeach; ?> </div> 

Something like that would be to: enter image description here

  • The question is not entirely clear, do you have an example? - E_p
  • extract() - bad, it is not clear where and some variables come from. - E_p

0