Skip to content

Instantly share code, notes, and snippets.

Created March 2, 2009 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/73014 to your computer and use it in GitHub Desktop.
Save anonymous/73014 to your computer and use it in GitHub Desktop.
<?PHP
// First off, how many items per page?
$per_page = 4;
// Next, get the total number of items in the database
$num_videos = $db->getValue("SELECT COUNT(*) FROM videos where status = 'approved' ORDER BY dt");
// Initialize the Pager object
$pager = new Pager($_GET['p'], $per_page, $num_videos);
// Using the data that $pager calculated for us, select the appropriate records from the database
$videos = DBObject::glob('video', "SELECT * FROM videos WHERE status = 'approved' ORDER BY dt DESC LIMIT {$pager->firstRecord}, {$pager->per_page}");
?>
<html>
<body>
<p>You are viewing videos <?PHP echo $pager->firstRecord; ?> through <?PHP echo $pager->lastRecord; ?>
of <?PHP echo $pager->numRecords; ?> total.</p>
<?PHP foreach($videos as $v) : ?>
<!-- Do something with the video - display it perhaps -->
<?PHP endforeach; ?>
<!-- Simple Previous/Next links -->
<a href="some-page.php?p=<?PHP echo $p->prevPage(); ?>">Previous Page</a>
<a href="some-page.php?p=<?PHP echo $p->nextPage(); ?>">Next Page</a>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment