Separating large amounts of data into pages?
Posted: Sat Feb 13, 2010 11:28 am
Basically I have a table full of NPCs that the player can hire for my racing game. Right now, every single entry in that table is printed on one page.
I've been trying to work out how to add a "X entries per page" feature, where the number X could be changed by the user to suit his own needs.
As it is now, I have a while loop that runs through an array that contains all NPCs, and prints to a table.
Ignore the NPC names, I've not implemented a way of generating different names yet :p
The problem here is that I need page one to show the 25 first entries in the array on page one, 26-50 on page 2, and so on until last item is shown.
I've fiddled some with the code layout shown below, which enables me to print only the first 25 entries, but the problem starts with the "next page", where I need to print entries 26 through 50 etc.
Anyone got any good ways of doing what I want?
I've been trying to work out how to add a "X entries per page" feature, where the number X could be changed by the user to suit his own needs.
As it is now, I have a while loop that runs through an array that contains all NPCs, and prints to a table.
Ignore the NPC names, I've not implemented a way of generating different names yet :p
The problem here is that I need page one to show the 25 first entries in the array on page one, 26-50 on page 2, and so on until last item is shown.
I've fiddled some with the code layout shown below, which enables me to print only the first 25 entries, but the problem starts with the "next page", where I need to print entries 26 through 50 etc.
Code: Select all
$npc_data = getAllNPCs();
$counter = 0;
$row_limit = 25;
while($rows = mysql_fetch_array($npc_data)) {
// set up local variables to fetch current array data
$counter++;
// Print fetched data to a HTML table
if($counter % $row_limit == 0) {
// stop printing, we've reached the row limit
}
}