Skip to content

Instantly share code, notes, and snippets.

@nixon1333
Last active December 2, 2015 04:28
Show Gist options
  • Save nixon1333/434945ec49ca11d41c99 to your computer and use it in GitHub Desktop.
Save nixon1333/434945ec49ca11d41c99 to your computer and use it in GitHub Desktop.
pagination
<?php if ((ceil($usersTotal / $perPage)) >= 2) { ?>
<ul class="pagination pagination-sm no-margin pull-right">
<?php if ($currentPage != 1): ?>
<li>
<a href="<?php echo base_url() ?>super/users_list">&laquo;</a>
</li>
<?php endif; ?>
<?php
$loopThrough;
$loopStart;
$lastPage = ceil($usersTotal / $perPage);
if ($currentPage == 1) {
$loopStart = 1;
$loopThrough = $loopStart + 4;
$loopThrough = ($loopThrough > $lastPage) ? $lastPage : $loopThrough;
} else if ($currentPage == $lastPage) {
$loopThrough = $lastPage;
$loopStart = $lastPage - 5;
$loopStart = ($loopStart < 1) ? 1 : $loopStart;
} else {
$loopStart = $currentPage - 2;
$loopStart = ($loopStart < 1) ? 1 : $loopStart;
$loopThrough = $loopStart + 5;
$loopThrough = ($loopThrough > $lastPage) ? $lastPage : $loopThrough;
}
?>
<?php
for ($loopStart; $loopStart <= $loopThrough; $loopStart++) { ?>
<li class="<?php if ($loopStart == $currentPage) { ?> active <?php } ?>">
<a href="<?php echo base_url() ?>super/users_list/<?php echo $loopStart ?>">
<?php echo $loopStart ?>
</a>
</li>
<?php } ?>
<?php
if ($currentPage != $lastPage): ?>
<li>
<a href="<?php echo base_url() ?>super/users_list/<?php echo $lastPage ?>">
&raquo;
</a>
</li>
<?php endif; ?>
</ul>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment