Skip to content

Instantly share code, notes, and snippets.

@jordanandree
Created December 27, 2010 23:25
Show Gist options
  • Save jordanandree/756698 to your computer and use it in GitHub Desktop.
Save jordanandree/756698 to your computer and use it in GitHub Desktop.
<?php
function paginate( $total, $perpage )
{
$current = $_GET['page'] != '' ? $_GET['page'] : 1;
$paginate = '<div>';
$paginate .= $current > 1 ? '<a href="?page='.($current-1).'"> &laquo; Older |</a>' : '';
$paginate .= '<div>';
for($i = 1; $i <= round($total/$perpage); $i++ ){
$paginate .= '<a href="?page='.$i.'">'.$i."</a>";
}
$paginate .= '</div>';
$paginate .= $current <= ($total/$perpage) ? '<a href="?page='.($current+1).'"> | Newer &raquo;</a>' : '';
$paginate .= '</div>';
return $paginate;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment