Created
January 26, 2017 15:51
-
-
Save yumyo/4244058049c70794574c8bbe770a28a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$items = array(1,2,3,4,5,6,7,8,9,10,11,12); | |
$limit = 5; | |
$qty_items = count($items); | |
$qty_pages = ceil($qty_items / $limit); | |
$curr_page = isset($_GET['page']) ? $_GET['page'] : 1; | |
$next_page = $curr_page < $qty_pages ? $curr_page + 1 : null; | |
$prev_page = $curr_page > 1 ? $curr_page - 1 : null; | |
$offset = ($curr_page - 1) * $limit; | |
$items = array_slice($items, $offset, $limit); | |
?> | |
<style> | |
.curr{ | |
border:1px solid #ddd; | |
padding:3px; | |
} | |
</style> | |
<ul> | |
<? foreach($items as $item): ?> | |
<li><?= $item ?></li> | |
<? endforeach ?> | |
</ul> | |
<? if($prev_page): ?> | |
<a href="pager.php?page=<?= $prev_page ?>"> << </a> | |
<? endif ?> | |
<? for($i = 1; $i <= $qty_pages; $i++): ?> | |
<a href="pager.php?page=<?= $i ?>" class="<?= ($i == $curr_page) ? 'curr' : '' ?>"><?= $i ?></a> | |
<? endfor ?> | |
<? if($next_page): ?> | |
<a href="pager.php?page=<?= $next_page ?>"> >> </a> | |
<? endif ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment