paging through an array

Results 1 to 3 of 3

Thread: paging through an array

  1. #1
    Join Date
    Dec 1969

    Default paging through an array

    I have a large 2d array I need to output to the screen in 50 row chunks with a link at the bottom of the page to see the next 50. I currently am outputing the whole array but it is often too large and takes a long time to display. I need the somehow loop through the array output 50 rows at a time keeping track of the last page and dynamically build the next 50 link. How can I do this?

  2. #2
    Join Date
    Dec 1969

    Default Make some variabes..

    You just need to make some variables to keep track of it. Your trying to make your own paginator. Variables you&#039;ll need.<BR><BR>&#039;&#039;&#039;&#039;&#039;&#039;* **************THe following is just a demonstration of the logic you will need. I didnt test the code. Its up to you to make it work.<BR><BR><BR>Dim PageNum &#039;&#039;&#039;&#039;The page number of the results<BR>Dim MaxRecords &#039;&#039; The maximum amount of records per page<BR>Dim StartRecord &#039;&#039;The record to start on-depends on (page-1) * <BR>Dim TotalRecords<BR><BR>MaxRecords = 50<BR>TotalRecords = ubound(yourarray)<BR><BR>&#039;&#039;&#039; Use querystring to pass pageNum if querystring empty assume 1<BR><BR>If not IsEmpty(request.querystring("pageNum")) then<BR> PageNum = cint(request.querystring("pageNum"))<BR>Else <BR> PageNum = 1<BR>End if<BR><BR><BR>&#039;&#039;&#039;Determine start record<BR>StartRecord = (PageNum-1) * MaxRecords<BR><BR>&#039;&#039;&#039;List your results<BR>For x = StartRecord to MaxRecords-1<BR> &#039;&#039;&#039;TODO: ADD YOUR LISTING LOGIC<BR> <BR> &#039;&#039;&#039; No more records in the array. Exit loop<BR> If x = TotalRecords then<BR> exit for<BR> End if<BR>Next<BR><BR>Your next and back buttons should contain pageNum + 1 or pageNum -1 respectively. <BR><BR>If you are using Recordset.getrows to get the array there are some optimizations you can do to this code to consume less memory by only retrieving the rows you need. The idea is to use rs.move to move to the StartRecord then use rs.getrows(maxrows) to get the records you need. Then close the rs and the conn.

  3. #3
    Join Date
    Dec 1969

    Default Interesting...

    The question is a crosspost, but I find it interesting that you jumped right to the assumption that he&#039;s getting the data from a RecordSet. If you are right, then I agree with you (and said so in the other thread). Much better to do in the query than otherwise.<BR><BR>But if you are wrong, do you see any solution except Session variable(s)?<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts