From: "Brent Baisley" <[EMAIL PROTECTED]>

You hardly need a library for figuring out pagination. A very simple
formula tells you how many "pages" you have.
$itemsPerPage = 10;
$totalRecords = 52; //Result of SELECT FOUND_ROWS()
$pages = ceil($totalRecords/$itemsPerPage);

Based on those numbers, you know you have 6 pages of data. You can
then create a loop to generate the links with the proper parameter (s),
however you want to format them.

On Oct 18, 2007, at 5:27 PM, Ben Sgro ((ProjectSkyLine)) wrote:
Sure, I guess that's a fine way to do it.
I'll just toss it into a class for reuseability.


Here's my version of such a class:
http://dev.dellsala.com/source/Pager.phps

An example of how it might be used:

$pager = new Pager();
$pager->setItemsPerPage(10);
$pager->setCurrentPage(2);   // from $_POST or $_GET

// generate your query LIMIT
$sqlLimit = "LIMIT {$pager->getItemOffset()}, {$pager->getItemsPerPage ()}";

$pager->setItemCount(125);   // from SELECT FOUND_ROWS(). thanks brent!

// output the paging interface
?>
<p>Page <?php echo $pager->getCurrentPage(); ?> of <? echo $pager- >getPageCount(); ?></p> <a href="search.php?page=<?php echo $pager->getPreviousPage(); ? >">Previous</a>
<a href="search.php?page=<?php echo $pager->getNextPage(); ?>">Next</a>

-- Dell

_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php

Reply via email to