Forum Moderators: coopster

Message Too Old, No Replies

pagination based on array count

         

danielm28

11:59 pm on Feb 21, 2005 (gmt 0)

10+ Year Member



Hello, I am modifying pagination on a dealer list page. Originally, this was based on how many rows came back from the db. I would now like to change it to create pagination based on how many rows are in an array.
Any help would be greatly appreciated.
here's the code that I already have. I have included a note as to where I'm having the problem:

# Use the incoming 'chunk' parameter to
# select only a slice of the data for display.
#
$chunk_size = 10;
$offset = $chunk_size * $chunk;
$previous = $chunk - 1;
$next = $chunk + 1;
$starting_record = $chunk * $chunk_size + 1;
$ending_record = ($chunk + 1) * $chunk_size;

# Determine the total number of dealers matching the criteria.
$num_dealers = count($listingziparray);

$last = floor($num_dealers/$chunk_size);
if ($ending_record > $num_dealers)
{
$ending_record = $num_dealers;
}

# Now retrieve the actual data in the array, limiting the number
# of results according to the chunk size.
#

THIS IS WHERE I'M HAVING THE PROBLEM. I DON'T KNOW HOW TO LIMIT THE ARRAY RESULTS.
THE FOLLOWING CODE IS WHAT I USED WHEN DEALING WITH DATA FROM DB:
//$where .= " LIMIT $offset, $chunk_size";

//$query = "SELECT * FROM dealer $where";
//$result = mysql_query($query);

RyanM

12:15 am on Feb 22, 2005 (gmt 0)

10+ Year Member



Hi I dont know if this will solve it but use the for each loop untill you get to the required chunk size, and then break the loop. Pass the array through the session variables, and if I am not wrong you should keep the pointer at the right location. This way you also do not need to tax the database for every page request.

danielm28

12:40 am on Feb 22, 2005 (gmt 0)

10+ Year Member



i have fixed this problem by using
array_slice($listingziparray, $offset, $chunk_size);