Last active
February 14, 2018 03:53
-
-
Save munsiwoo/582fed3c2ea7de647a9c96ce62e318a2 to your computer and use it in GitHub Desktop.
pagination
This file contains 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 | |
function pagination($page, $limit, $count) { | |
echo "<style>a { text-decoration:none; color:black; }</style>"; | |
for($x = ($page-1); ($x%$limit) != 0; --$x); | |
if(($page-1) >= $limit) { | |
echo "<a href=\"?page={$x}\"><Prev</a> "; | |
} | |
$limit = (($x+$limit) > $count) ? $count : $x+$limit; | |
for($p = ($x+1); $p <= $limit; ++$p) { | |
if($p == $page) echo "<b><a href=\"?page={$p}\">{$p}</a></b> "; | |
else echo "<a href=\"?page={$p}\">{$p}</a> "; | |
} | |
if($p <= $count) { | |
echo "<a href=\"?page={$p}\">Next></a>"; | |
} | |
} | |
if(!isset($_GET['page']) || $_GET['page'] < 1) { | |
header('Location: ?page=1'); | |
} | |
$page = (int)$_GET['page']; // select page | |
$limit = 5; // divide | |
$count = 23; // total number of pages | |
echo '<pre>'; | |
echo "total page : {$count}".PHP_EOL; | |
pagination($page, $limit, $count); | |
echo '</pre>'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment