views:

1440

answers:

8

How are paged results commonly implemented in PHP?

I'd like to have a results page with 10 results. Paging forward in the navigation would give me the next and previous sets.

Is there a way this is commonly done? Does anyone have simple advice on getting started?

A: 

The term you are referring to is "pagination". Unfortunately you'll have to give some more information to get a more specific answer.

Factor Mystic
A: 

What you are looking for is called pagination. There have been several questions on SO about this subject. As your question is very broad, please provide more details or refer to the questions that have already been asked about this subject.

Aron Rotteveel
+3  A: 

You'll need a beginner's understanding of PHP, and probably some understanding of relational databases.

Pagination is often implemented with some simple query parameters.

stackoverflow.com/myResults.php?page=1

The page increments the query parameter:

stackoverflow.com/myResults.php?page=2

On the back end, the page value usually corresponds to the limits and offsets in the query that is being used to generate the results.

Related Questions:

keparo
A: 

It may be worth looking at the Zend Framework's Zend_Paginator object. It encapsulates a lot of the logic of generating next/previous/first/last type links.

Ciaran McNulty
A: 

The TinyButStrong template system comes with a pagination extension. Very easy to use.

Cruachan
A: 

Just Google for php+pagination

troelskn
A: 

If database is not so big - I implement pagination on client side. I recommend jquery plugin tablefilter - it gives you not only pagination, but also filtering and sorting. You can easily browse through given recordset. It's very good solution if performance is not very important. There's page: http://ideamill.synaptrixgroup. and demo for 830 records: http://ideamill.synaptrixgroup.com/jquery/tablefilter/largetabletest.htm

pbrodka
A: 

For server-side paging, I use PEAR's Pager package (http://pear.php.net/package/Pager).

Take a look at example.php for basic usage, and Page_Wrapper.php (I started with Pager_Wrapper_DB).

The end-user docs are quite comprehensive: http://pear.php.net/manual/en/package.html.pager.intro.php

starmonkey