-
-
Save qichunren/315592 to your computer and use it in GitHub Desktop.
simple php framework的分页
This file contains hidden or 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 | |
// 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