Skip to content

Instantly share code, notes, and snippets.

@kinobi
Created August 3, 2012 09:20
Show Gist options
  • Save kinobi/3246229 to your computer and use it in GitHub Desktop.
Save kinobi/3246229 to your computer and use it in GitHub Desktop.
Pagination function
function pagination($total, $per_page, $page, $start){
$requiredPages = ceil($total/$per_page);
$whichPage= $start/$per_page+1;
$start = "-".$per_page;
echo "<ul class='pagination'><li>Page</li>";
for ($i = 1; $i <= $requiredPages; $i++) {
$start = $start+$per_page;
if($i==$whichPage){
echo '<li class="active">'.$i."</li>";
}
else {
echo "<li><a href='".SITE_URL.$page."/".$start."'>".$i."</a></li>";
}
}
echo "</ul>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment