Last active
August 29, 2015 14:14
-
-
Save p810/6074070e85b49c9c5a73 to your computer and use it in GitHub Desktop.
PHP code for 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 | |
$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