Skip to content

Instantly share code, notes, and snippets.

@p810
Last active August 29, 2015 14:14
Show Gist options
  • Save p810/6074070e85b49c9c5a73 to your computer and use it in GitHub Desktop.
Save p810/6074070e85b49c9c5a73 to your computer and use it in GitHub Desktop.
PHP code for pagination.
<?php
$page = $_GET['page'];
$limit = 12;
if(!is_numeric($page)) {
$page = 1;
}
$end = $limit * $page;
$offset = ($end - ($limit - 1));
$results = "SELECT * FROM `photos` WHERE `albumid` = '14' LIMIT $offset, $end";
$total = "SELECT COUNT(*) FROM `photos` WHERE `albumid` = '14' AND `photoid` > $end";
// For pagination, this is how you'd determine whether to show next/prev buttons
if($page > 1) {
// show the prev button
}
if($total > 0) {
// show the next button
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment