If you are using a content management system and or a database, then you will need to use a “paging” module in that CMS to get these links and the filtered number of results.
Here’s a long-hand example: if you were showing all the products in your database, you might have something like this in your controller (MyActiveRecord example code):
$products = Product::FindAll('for_sale = 1');
And in your view, you would iterate over these:
foreach($products as $product){
render_partial('list_item',$product);
}
So if you follow this example, you would then need to limit the initial request, to something like this:
$offset = (present($_GET['offset'])) ? (int) $_GET['offset'] : 0;
$products = Product::FindAll('for_sale = 1', 10, $offset);
The first line just cleans up the page attribute passed in through the URL, and the second uses that variable to get the next 10 records.
You would form your previous and next URLs by adding or removing 10 from the $offset integer, and testing to be sure that there were some results:
$prev_link = ($offset - 10 > 0) '?offset=' . ($offset - 10) : '#';
$next_link = (Product::Count('for_sale = 1') >= $offset + 10) '?offset=' . ($offset + 10) : '#';
As for getting the 2,3,4,5 links in between, that takes an iterative function that basically tests the offset at each step and generates a link. I don’t have an example for that handy, but it’s not that complex to write.
Walter
On May 29, 2012, at 3:21 PM, David Wise wrote:
Does anyone know how to create a button similar to below, I have a lot of stock on some pages, and rather than having a page that just keeps growing in length, I would rather have a page full, then at the bottom, a way that customer can get to next page to view more stock, then scroll back or forward if needed
<First<Previous 12345 next> last>
freewaytalk mailing list
email@hidden
Update your subscriptions at:
List Options | FreewayTalk
freewaytalk mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options