Cześć. Oczywiście jako że jestem zupełnym gamoniem i nie mogłem nigdzie znaleźć rozwiązania problemu, szukam tutaj. I wiem że problem był poruszany kilka razy, ale nie mogłem tam tego znaleźć.

Zapożyczyłem sobie + trochę zedytowałem klasę która pojawiła się tu wcześniej na forum.

  1. <?php
  2. require 'pagination.class.php';
  3.  
  4. $tablica = glob ("*.*g");
  5. $razem = count($tablica);
  6.  
  7. $pag = new Pagination();
  8. $pag->setTotalCount(count($tablica));
  9. $pag->setCurrentPage(empty($_GET['page']) ? 0 : $_GET['page']);
  10.  
  11.  
  12. for($i = $pag->indexStart(); $i <= $pag->indexEnd(); $i++)
  13. {
  14. echo $tablica[$i].'<br>'.PHP_EOL;
  15. }
  16.  
  17. echo $pag->getHtml();
  18. ?>


Oczywiście nic zupełnie na stronie się nie zmienia. Co robię źlę?
Jedyne co myślę że może się nie zgadzać to to, że w standardzie w kodzie 4 i 5 linijki wyglądały tak:

  1. $tablica = glob ("*.*g");
  2.  
  3. $razem = count($tablica1);


Ale oczywiście zmienna $tablica1 nie jest zdefiniowana, więc to zmieniłem. Wcześniej wyrzucało błąd.
Pewnie pytanie durne i wyjdę na idiotę, ale dopiero zaczynam naukę wink.gif

Tutaj sama klasa:
  1. <?php
  2.  
  3. /**
  4. * @package sequence
  5. * @subpackage util
  6. * @author Filip Szczechowiak <filip.szczechowiak@gmail.com>
  7. */
  8.  
  9. class Pagination
  10. {
  11. protected $currentPage;
  12. protected $perPage;
  13. protected $totalCount;
  14. protected $range;
  15. protected $baseLink;
  16. protected $link;
  17. protected $navBack;
  18. protected $navNext;
  19. protected $html;
  20.  
  21. public function __construct()
  22. {
  23. $this->currentPage = 1;
  24. $this->perPage = 20;
  25. $this->totalCount = 24;
  26. $this->range = 3;
  27. $this->url = '?page=#PAGE#';
  28. $this->baseUrl = $_SERVER['SCRIPT_NAME'];
  29. $this->navBack = 'Poprzednia';
  30. $this->navNext = 'Następna';
  31. $this->html = null;
  32. }
  33.  
  34. /**
  35.   * Ustawia aktualną stronę
  36.   *
  37.   * @param int $val - aktualna strona
  38.   * @return Pagination
  39.   */
  40. public function setCurrentPage($val)
  41. {
  42. $val = (int) $val;
  43.  
  44. if($val === 0 || $val > $this->totalPages())
  45. {
  46. $this->currentPage = 0;
  47. } else
  48. {
  49. $this->currentPage = $val;
  50. }
  51.  
  52. return $this;
  53. }
  54. /**
  55.   * Ustawia ilość wyświetlanych wierszy na stronie.
  56.   *
  57.   * @param int $val - ilość wyświetlanych wierszy na stronie
  58.   * @return Pagination
  59.   */
  60. public function setPerPage($val)
  61. {
  62. $this->perPage = $val;
  63.  
  64. return $this;
  65. }
  66.  
  67. /**
  68.   * Ustawia ilość wszystkich wierszy.
  69.   *
  70.   * @param int $val - ilość wszystkich wierszy
  71.   * @return Pagination
  72.   */
  73. public function setTotalCount($val)
  74. {
  75. $this->totalCount = $val;
  76.  
  77. return $this;
  78. }
  79.  
  80. /**
  81.   * Ustawia ilość wyświetlanych stron, przed i za aktualną stroną.
  82.   *
  83.   * @param int $val - ilość stron
  84.   * @return Pagination
  85.   */
  86. public function setRange($val)
  87. {
  88. $this->range = $val;
  89.  
  90. return $this;
  91. }
  92.  
  93. /**
  94.   * Ustawia podstawowy link, bez paginacji (pierwsza strona), przykładowo:
  95.   * - /custompage
  96.   * - custompage.php
  97.   *
  98.   * @param string $val - podstawowy link
  99.   * @return Pagination
  100.   */
  101. public function setBaseUrl($val)
  102. {
  103. $this->baseUrl = $val;
  104.  
  105. return $this;
  106. }
  107.  
  108. /**
  109.   * Ustawia link z paginacją, przykładowo:
  110.   * - /custompage/page/#PAGE#
  111.   * - custompage.php?page=#PAGE#
  112.   *
  113.   *
  114.   * @param string $val - link z dodatkowa paginacja
  115.   * @return Pagination
  116.   */
  117. public function setUrl($val)
  118. {
  119. $this->url = $val;
  120.  
  121. return $this;
  122. }
  123.  
  124. /**
  125.   * Zmienia nazwę przycisku "poprzedni", możliwe jest też wstawienie kodu html,
  126.   * naprzykład obrazka, bądź jakiegoś innego elementu.
  127.   *
  128.   * @param mixed $val - nazwa przycisku "poprzedni"
  129.   * @return Pagination
  130.   */
  131. public function navBack($val)
  132. {
  133. $this->navBack = $val;
  134.  
  135. return $this;
  136. }
  137.  
  138. /**
  139.   * Zmienia nazwę przycisku "następny", możliwe jest też wstawienie kodu html,
  140.   * naprzykład obrazka, bądź jakiegoś innego elementu.
  141.   *
  142.   * @param mixed $val - nazwa przycisku "nastepny"
  143.   * @return Pagination
  144.   */
  145. public function navNext($val)
  146. {
  147. $this->navNext = $val;
  148.  
  149. return $this;
  150. }
  151.  
  152. /**
  153.   * @return int - zwraca całkowitą liczbe stron
  154.   */
  155. protected function totalPages()
  156. {
  157. return $this->totalCount >= $this->perPage ? ceil($this->totalCount/$this->perPage) : 1;
  158. }
  159.  
  160. /**
  161.   * @return int - zwraca poprzedną stronę
  162.   */
  163. protected function previousPage()
  164. {
  165. return $this->currentPage-1;
  166. }
  167.  
  168. /**
  169.   * @return int - zwraca następną stronę
  170.   */
  171. protected function nextPage()
  172. {
  173. return $this->currentPage+1;
  174. }
  175.  
  176. /**
  177.   * @return string - zwraca podmieniony fragment linka
  178.   */
  179. protected function createLink($page)
  180. {
  181. if(1 == $page)
  182. {
  183. return $this->baseUrl;
  184. } else
  185. {
  186. return str_replace('#PAGE#', $page, $this->url);
  187. }
  188. }
  189.  
  190. /**
  191.   * Zwraca początek ilości wyświetlanych wierszy.
  192.   *
  193.   * @return int - początek przedziału
  194.   */
  195. public function offset()
  196. {
  197. if($this->currentPage > 1)
  198. {
  199. return $this->currentPage * $this->perPage - $this->perPage;
  200. } else
  201. {
  202. return 0;
  203. }
  204. }
  205.  
  206. /**
  207.   * Zwraca przedział ilości wyświetlonych wierszy.
  208.   *
  209.   * @return int - koniec przedziału
  210.   */
  211. public function limit()
  212. {
  213. return $this->perPage;
  214. }
  215.  
  216. /**
  217.   * Zwraca pierwszy indeks tablicy.
  218.   *
  219.   * @return int - pierwszy indeks tablicy
  220.   */
  221. public function indexStart()
  222. {
  223. if($this->currentPage > 1)
  224. {
  225. $result = $this->perPage * ($this->currentPage - 1);
  226. } else
  227. {
  228. $result = 0;
  229. }
  230.  
  231. return $result;
  232. }
  233.  
  234. /**
  235.   * Zwraca ostatni indeks tablicy.
  236.   *
  237.   * @return int - ostatni indeks tablicy
  238.   */
  239. public function indexEnd()
  240. {
  241. if($this->totalCount > $this->perPage)
  242. {
  243. $val = $this->indexStart() + ($this->perPage - 1);
  244. if($val > $this->totalCount)
  245. {
  246. $result = $this->totalCount - 1;
  247. } else
  248. {
  249. $result = $val;
  250. }
  251. } else
  252. {
  253. $result = $this->totalCount - 1;
  254. }
  255.  
  256. return $result;
  257. }
  258.  
  259. /**
  260.   * Zwraca wygenerowany kod html pagera.
  261.   *
  262.   * @param string $style - dodatkowy parametr przeznaczony dla lokalnych styli
  263.   * @return string - zwraca wygenerowany kod html
  264.   */
  265. public function getHtml($style = null)
  266. {
  267. if(null !== $this->html)
  268. {
  269. return $this->html;
  270. }
  271.  
  272. if ($this->totalCount <= $this->perPage)
  273. {
  274. return '';
  275. }
  276.  
  277. $res = '';
  278.  
  279. if($this->currentPage >= 2)
  280. {
  281. $res = '<a href="'.$this->createLink($this->previousPage()).'" class="previous_page"><span>'.$this->navBack.'</span></a> ';
  282. if($this->currentPage > ($this->range + 1))
  283. {
  284. if(1 === $this->currentPage)
  285. {
  286. $res .= ' <span class="selected">1</span> ';
  287. } else
  288. {
  289. $res .= ' <a href="'.$this->createLink(1).'">1</a>';
  290. }
  291.  
  292. if($this->currentPage > ($this->range + 2))
  293. {
  294. $res .= ' <span class="dotted">...</span> ';
  295. }
  296. }
  297. }
  298.  
  299. $idxFst = max($this->currentPage - $this->range, 1);
  300. $idxLst = min($this->currentPage + $this->range, $this->totalPages());
  301.  
  302. for($i = $idxFst; $i <= $idxLst; $i++)
  303. {
  304. if($i == $this->currentPage)
  305. {
  306. $res .= ' <span class="selected">'.$i.'</span> ';
  307. } else
  308. {
  309. $res .= ' <a href="'.$this->createLink($i).'">'.$i.'</a> ';
  310. }
  311. }
  312.  
  313. if($this->nextPage() <= $this->totalPages())
  314. {
  315. if($this->currentPage < ($this->totalPages() - $this->range))
  316. {
  317. if($this->currentPage < ($this->totalPages() - ($this->range + 1)))
  318. {
  319. $res .= ' <span class="dotted">...</span> ';
  320. }
  321.  
  322. $res .= ' <a href="'.$this->createLink($this->totalPages()).'">'.$this->totalPages().'</a> ';
  323. }
  324.  
  325. $res .= ' <a href="'.$this->createLink($this->nextPage()).'" class="next_page"><span>'.$this->navNext.'</span></a> ';
  326. }
  327.  
  328. $this->html = '<div class="pagination"'.(null === $style ? null : 'style="'.$style.'"').'>'.$res.'</div>';
  329.  
  330. return $this->html;
  331. }
  332. }
  333. ?>


Pozdrawiam i z góry dzięki za odpowiedź.