Perfect PHP Pagination

The script works well, but how can I convert this so that it reads information out of my database? I also need to be able to have multiple column of data, is this possible to do?

Dan.

I don’t know PHP that well. I’m a Ruby guy. But this is what I’d expect from a pagination lib and was incredibly simple to work with & extend.

Hey, awesome tutorial, works very well with personal extension, one thing (minor cosmetic fix); in your doublebarlayout.php, in order to keep consistency, put the “next” before the “last” at the very end of the file

I can’t say this class seems practical to use. It could be made so much more simpler than it is.

For example, my pagination class you pass a result set, batch number (number of records to show at any one time) and the current page number. Job’s a good 'un.

I don’t know, I find the following much easier myself


$paginator = Zend_Paginator::factory($rowset)
                 ->setCurrentPageNumber(3);

echo $paginator;

I have tried to implement this class (which I love, by the way). It offers me the ability to enter my own query AND results display, which I haven’t found anywhere else. I do have one question and am unsure of where to post it. Could someone please help me figure out where to post a question regarding the target being a page “included” in a div via a database query?

hi hapagirl and welcome to the forums :wave:

Post your question in the main PHP forum.

I love this Pagination!

Fatal error: Interface ‘PageLayout’ not found in [path]\DoubleBarLayon line 4

This is still not working for me either!!

Did anyone find a solution?

Colin

SOLVED:

require_once “DoubleBarLayout.php”; was needed.

Nice script. How do I display a list of clickable urls per page without a database?

The included example displaying names works fine. However, if I could figure out how to display only urls and have them appear in a 350 pixel wide table, the script would be perfect.

ex.

clickablelink1.php
clickablelink2.php
clickablelink3.php
clickablelink4.php
…etc.

Using…

<?php
require_once “Paginated.php”;
require_once “DoubleBarLayout.php”;
?>
<html>
<head>
<title>Pagination</title>

<!-- Just a little style formatting. Has no bearing on example –>
<style type=“text/css”>
body {
font-family: Verdana;
font-size: 13px;
}

a {
	text-decoration: none;
}

a:hover {
	text-decoration: underline;
}

</style>
<!-- End style formatting –>
</head>

<body>

&lt;?php
//create an array of names in alphabetic order. A database call could have retrieved these items
$names = array("Andrew", "Bernard", "Castello", "Dennis", "Ernie", "Frank", "Greg", "Henry", "Isac", "Jax", "Kester", "Leonard", "Matthew", "Nigel", "Oscar");

$page = $_GET['page'];

//constructor takes three parameters
//1. array to be paged
//2. number of results per page (optional parameter. Default is 10)
//3. the current page (optional parameter. Default  is 1)
$pagedResults = new Paginated($names, 10, $page);

echo "&lt;ul&gt;";

while($row = $pagedResults-&gt;fetchPagedRow()) {	//when $row is false loop terminates
	echo "&lt;li&gt;{$row}&lt;/li&gt;";
}

echo "&lt;/ul&gt;";

//important to set the strategy to be used before a call to fetchPagedNavigation
$pagedResults-&gt;setLayout(new DoubleBarLayout());
echo $pagedResults-&gt;fetchPagedNavigation();
?&gt;

</body>
</html>

I want to paginate a list of article titles and output results as list of clickable URLS (20 per page).

Hi, nice article! But i dont understand how i can get data from a mysql database insted of an array. Can somebody show my how i will make the query and where to use mysql_fetch_assoc or mysql_fetch_array? And how do i loop the fetch to get all the rows in there?

Look at this thread. This may help. It may be a bit complex since it uses queries but also classes.

For something far more simple, this could help

http://www.php-mysql-tutorial.com/wikis/php-tutorial/paging-using-php.aspx