Solved

Need Help with Paging through record set - AbsolutePage is forbidden on the server

Posted on 2006-07-01
9
363 Views
Last Modified: 2008-02-20
I usually use absolutepage to page through my results - however, on this server, it is not allowed.

I need a way to page through, count records and add page numbers to the top and bottom of results.

I want to display the total records found at the top like "There were X peoperties that matched your criteria", then display 10 records per page - here is a code example that I already have in place.  Can someone help?



<%
rs.open "select * from properties where criteria = '"&criteria1&"'",conn,3,3

while not rs.eof
getdetails = rs("getdetails")

%>
The table and all the details goes here

<%
rs.movenext
wend
rs.close

%>
0
Comment
Question by:foreverdita
9 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
Just search for "paging" in this Topic Area and you will get hundreds of solutions.
0
 

Author Comment

by:foreverdita
Comment Utility
I did, however, the ones I found that looked like what I wanted to do all used AbsolutePage.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
I came up with over 4000 hits in this Topic Area alone using the following search criteria:
Title:  Contains All  'paging'
Everything:  Does Not Contain  'absolutepage'

But probably your best choice if AbsolutePage is "not allowed" (this rule seems insane, was there any reason given) is to save the recordset to an array using the GetRows method and keeping tabs of where you are within the recordset.

A probably more important question is what database are you using, as the answer will no doubt be influenced by that.
0
 

Author Comment

by:foreverdita
Comment Utility
It is sqlserver 2000

Yes, I searched through about 6 pages before posting my question and tried 4 examples of a GetRow function - they all seem to use some type of absolute.  I just tried one that did not use absolutepage, said it used getrow and then used a absoluteposition, which gave me the same error.

Security was the reason given by the provider and there is no ifs ands or buts they said - they won't allow it.

The arrays seemed like they would work, but it used the absoluteposition in both examples I found.  There was another example using javascript, but I would like to avoid that if possible.

I am still searching as well, but thought it would help if I posted and someone knew of a solution while I tried to find one as well - because each time I code out an example and it fails, I get more frustrated.

Yes, disallowing absolute seems absurd to me - I have never done it any differently.

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
This is how I would do it:  Write a stored procedure that accepts the parameters to search, as well as the page size, page index and optionally sort by and sort direction.  In addition it will have an output parameter of the total row count.

Your stored procedure will then query the tables and insert all the rows into a variable of type table that has a structure that matches the query with an additional column: ID which has an IDENTITY.  The insert will give you the total row count (@@ROWCOUNT) and the ID is used to only return the number of rows desired.  This should give you an idea:

Declare      @StartID integer,
      @EndID integer

-- Your Insert query goes here

Set @RowCount = @@ROWCOUNT

If (@PageIndex Is Null Or @PageSize Is Null)
   Begin
      Set @StartID = 0
      Set @EndID = @RowCount
   End
Else
   Begin
      Set @StartID = @PageIndex * @PageSize + 1
      Set @EndID = (@PageIndex + 1) * @PageSize
   End

Select      t.Column1,
      t.Column2,
      t.Column3,
      t.Column4,
      t.Column5,
      t.Column6,
      ...
      t.Columnn
From      @Temp t
Where      t.ID Between @StartID And @EndID
Order By t.ID


One caveat, in your ASP code you must close the recordset, before you attempt to read the Output parameter (@RowCount).  The best way to accomplish this is to use GetRows, close the recordset and then read @RowCount.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
You will still have to keep track of the PageIndex as the goes to the next or previous page, but this is just an integer and can be easily saved in a Session variable.
0
 
LVL 20

Expert Comment

by:Gawai
Comment Utility
0
 
LVL 11

Accepted Solution

by:
JohnModig earned 500 total points
Comment Utility
In classic ASP I personally like using the getrows function to collect the results from db and put them into an array this method is very fast (and much better than using .movenext) and then it is easy to page thru the array. Code should look something like this:
------------------------------------------------

'----------------------------------
'  Get the records
'----------------------------------
public sub getCategories
 sql = "SELECT getdetails " & _
 "FROM properties " & _
 "WHERE criteria = '" & criteria1 & "'"
 set rs = Server.CreateObject("ADODB.Recordset")
 rs.Open sql,conn
 'dump records in a multi-dimensional array(col,row)
 arrResults = rs.getrows
 'close recordset
 rs.close
 set rs=nothing
end sub

'-------------------------
'  Record paging
'-------------------------
 dim iStart, iOffset, txtOffset
 iStart = request.querystring("start")
 iOffset = request.querystring("offset")
 if Not IsNumeric(iStart) or Len(iStart) = 0 then
   iStart = 0
 else
   iStart = CInt(iStart)
 end if
 if Not IsNumeric(iOffset) or Len(iOffset) = 0 then
   iOffset = 10
 else
   iOffset = Cint(iOffset)
 end if
 dim iRows, iRowLoop, iStop
 iRows = UBound(arrResults, 2)
 if iRows => (iOffset + iStart) then
   iStop = iOffset + iStart - 1
 else
   iStop = iRows
 end If

'-------------------------
'  Create table for the results
'-------------------------
Body = "<table>" & vblf & _
"<tr><th>Getdetails</th></tr>" & vblf
'loop thru the results
for iRowLoop = iStart to iStop
  Body = Body & "<tr>" & vblf & _
  "<td>" & arrResults(0,iRowLoop) & "</td>" & _
  "</tr>" & vblf
next
Body = Body & "</table>" & vblf

'-------------------------
'  Text for navigating
'-------------------------
Body = Body & "<p>Displaying record " & iStart + 1 & " to " & iStop + 1 & " of " & uBound(arrArticles,2) + 1 & " total. " & vblf
  if iStart > 0 then
    'previous page link
    Body = Body & "| <a href=""mypage.asp?start=" & iStart-iOffset & "&amp;offset=" & iOffset & _
    """>Previous page</a>" & vblf
  end if
  if iStop < iRows then
    'next page link
    Body = Body & " | <a href=""mypage.asp?start=" & iStart+iOffset & "&amp;offset=" & iOffset & _
    """>Next page</a>" & vblf
  end if

'print everything
response.write Body
------------------------------------------------

Ok? Try this out and if you need more fields, simply specify them in the sql of the recordset (line 6):

  sql = "SELECT field1, field2, field3 "  ...

... and then use respectively column of the array to display the results, like this:
 
  " field1=" & arrResults(0,iRowLoop) & " field2=" & arrResults(1,iRowLoop) & " field3=" & arrResults(2,iRowLoop)

Remember arrays always start with 0 (zero) and not with 1.

Why getrows?:
http://www.learnasp.com/freebook/asp/whygetrows.aspx

Regards,
John
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
The problem with that approach with large data sets is that you have to return all the data every time, this would imply a heavy network performance hit.  Of course, if you are using the same server to host the IIS server as well as the database, you do not have these network issues, but then you have bigger problems ...
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now