Example:
A
B
C
D
E
F
G
H
I
J
there have 10 letter, i want to make a paging on per page show 5 letter.
Please someone help me.
$offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0
$on_page = 5;
$array = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
$count = count($array);
$array = array_slice($array, $offset, $on_page);
foreach($array as $value)
echo '<b>'.$value.'</b> ';
echo '<p>PAGES: ';
$col_page = round($count/$on_page);
for($page = 0; $p < $col_page; ++$p)
echo '<a href="?offset='.($p*$on_page).'">'.$p.'</a>';
echo '</p>';
<?php
$offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0;
$on_page = 5;
$array = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
$count = count($array);
$array = array_slice($array, $offset, $on_page);
foreach($array as $value)
echo $value;
echo '<p>PAGES: ';
$col_page = round($count/$on_page);
for($p = -1; $p < $col_page; ++$p)
echo '<a href="?offset='.($p*$on_page).'">'.($p+1).'</a>';
echo '</p>';
Вибачаюсь (треба перевіряти те що пишу Гг) $list = ['item1', 'item2', 'item3', /* more items... */];
$total = count($list);
$currentPage = isset($_GET['page']) ? intval($_GET['page']) : 1;
$itemsPerPage = 5;
$neighbours = 4;
$pagination = new \Kilte\Pagination\Pagination($total, $currentPage, $itemsPerPage, $neighbours);
$offset = $pagination->offset();
$limit = $pagination->limit();
$listing = array_slice($list, $offset, $limit);
foreach ($listing as $item) {
var_dump($item);
}
$pages = $pagination->build();
foreach ($pages as $num => $text) {
echo sprintf('<a href="?page=%s">%s</a><br />', $num, $text);
}