paging an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hame22
Forum Contributor
Posts: 214
Joined: Wed May 11, 2005 5:50 am

paging an array

Post by hame22 »

hi all,

I have an array of product codes $r

what i want to do is display a list of these codes but limit each page to just displaying 10 results, while using a paging system like << | 1 | 2 | >>

is this possible and any ideas on how to do this??


thanks

alex
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

This should give you an idea:

Code: Select all

<?php

if (!$n)
{
	$n = 0;
}

for ($i = $n; $i <= $n + 10); $i++) 
{
	print $r[$i]."<br />";
}

$next = $n + 10;
$prev = $n - 10;

print "<a href="thispage.php?n=$next">Next Page</a><br />
<a href="thispage.php?n=$prev">Previous Page</a>";

?>
You should be able to expand on that to do what you want.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

The best solution is to search this forum (or the complete internet) because you are not the first that asks this question..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

search term: pagination
Post Reply