Newsgroup: it.comp.www.asp
Titolo: problema con paginazione record

ciao a tutti
ho un problema con una pagina asp che estrae dei dati da una tabella e
li visualizza un record alla volta...il probleme è che quando arrivo
all'ultimo record, sulla pagina mi vengono visualizzati 2 i dati degli
ultimi 2 record, anzichè solo dell'ultimo....l'articolo l'ho trovato
su 
www.4guysfromrolla.com
 e l'ho modificato, in particolare ho
cambiato la query sql mettendo una clausola where che usa l'operatore
'like'...il codice è il seguente :
<!--#include file="../Connections/connessione.asp" -->
<%
  Dim iStart, iOffset
  iStart = Request("Start")
  iOffset = Request("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 = 1
  else
    iOffset = Cint(iOffset)
  end if
  Response.Write "Viewing " & iOffset & " records starting at record "
& iStart & "<BR>"
  Dim objConn, objRS
  Set objConn = Server.CreateObject("ADODB.Connection")
  'objConn.Open "DSN=MP3"
  objconn.open connstring
  Set objRS = Server.CreateObject("ADODB.Recordset")
  'objRS.Open "SELECT * FROM Mp3List", objConn
  sql="select articolo,li_desc0 from linsito where articolo like
'%12%'"
  set objrs=objconn.execute(sql)
  Dim aResults
  aResults = objRS.GetRows
  objRS.Close
  Set objRS = Nothing
  objConn.Close
  Set objConn = Nothing
  Dim iRows, iCols, iRowLoop, iColLoop, iStop
  iRows = UBound(aResults, 2)
  iCols = UBound(aResults, 1)
  If iRows > (iOffset + iStart) Then
    iStop = iOffset + iStart - 1
  Else
    iStop = iRows
  End If
  For iRowLoop = iStart to iStop
    For iColLoop = 0 to iCols
      Response.Write aResults(iColLoop, iRowLoop) & " "
    Next
    Response.Write "<BR>"
  Next  
  Response.Write "<P>"
  if iStart > 0 then
    'Show Prev link
    Response.Write "<A HREF=""getrows.asp?Start=" & iStart-iOffset & _
                   "&Offset=" & iOffset & """>Previous " & iOffset &
"</A>"
  end if
  if iStop < iRows then
    'Show Next link
    Response.Write " <A HREF=""getrows.asp?Start=" & iStart+iOffset &
_
                   "&Offset=" & iOffset & """>Next " & iOffset &
"</A>"
  end if
%>
avete idea di dove sia il problema?
grazie e ciao
sergio

Se può servire....
Sul sito MS, in italiano c'è un articolo
"Paging dei record da ASP "
che fornisce ottimi spunti per la paginazione.
Ecco lo script, ma sul sito è anche ben commentato.
<%@ Language=VBScript %>
<% Option Explicit %>
<SCRIPT LANGUAGE=VBScript RUNAT=SERVER>
   'Be sure to reference ADO Typelib or use ADOVBS.Inc
   Dim iPageNum, iRowsPerPage
   Main
      Sub Main()
   Dim rst
   Dim sSQL, sConnString
      If Request.QueryString("iPageNum") = "" Then
         iPageNum = 1
      Else
         iPageNum = Request.QueryString("iPageNum")
         iPageNum = CInt(iPageNum)
      End If
      iRowsPerPage = 10
      sConnString = "Provider=SQLOLEDB.1;password=Xyz123;user id=WebUser;" &
_
         "Initial Catalog=NorthWind;Data Source=MySQLServer;" & _
         "network=dbmssocn;"
      'The following SQL retrieves all columns from a SQL View.
      'To optimize performance:
      '- use a stored proc, a view, or specify columns in the SELECT
      '- use criteria to limit records returned (e.g. a WHERE clause)
      sSQL = "SELECT CategoryName, ProductName, QuantityPerUnit,"
      sSQL = sSQL & "UnitsInStock, Discontinued"
      sSQL = sSQL & " FROM [Products By Category]"
      Set rst = GetRecords(sConnString, sSQL)
      WriteTableHeader rst
      WriteTableBody rst, iRowsPerPage, iPageNum
      ShowNavBar rst
      'The ShowFastNavBar method does not use RecordCount
      'or PageCount so it only retries as many records
      'as dictated by the CacheSize of the Recordset
      'ShowFastNavBar rst
      CleanUp rst
   End Sub
   Function GetRecords(sConnString, sSQL)
   Dim cnn
   Dim rst
      set cnn = Server.CreateObject("ADODB.CONNECTION")
      cnn.ConnectionString = sConnString
      cnn.Open
      Set rst = Server.CreateObject("ADODB.RECORDSET")
      Set rst.ActiveConnection = cnn
      'CursorLocation of adUseClient would retrieve
      'all records when the Recordset is opened.
      'adUseServer allows us to leverage the CacheSize
      rst.CursorLocation = adUseServer
      'CacheSize limits rows fetched when using a
      'server-side cursor. We'll only grab the number
      'of records we are displaying - iRowsPerPage
      rst.CacheSize = iRowsPerPage
      rst.Open sSQL,,adOpenStatic, adLockReadOnly
      Set GetRecords = rst
   end Function
   Sub WriteTableHeader(rst)
   Dim fld
      Response.Write "<TABLE WIDTH=80% BORDER=1>"
      Response.Write "<TR>"
      'Build column titles for the table
      For Each fld in rst.Fields
         Response.Write "<TD><B>" & fld.Name & "</B></TD>"
      Next
      Response.Write "</TR>"
   End Sub
   Sub WriteTableBody(rst, iRowsPerPage, iPageNum)
   Dim iLoop
   Dim fld
      iLoop = 1
      rst.PageSize = iRowsPerPage
      rst.AbsolutePage = iPageNum
      'Write out the current page of records
      Do While (Not rst.EOF) and (iLoop <= iRowsPerPage)
         Response.Write "<TR>"
            For Each fld in rst.Fields
               Response.Write "<TD>" & fld.value & "</TD>"
            Next
         iLoop = iLoop + 1
         rst.MoveNext
         Response.Write "</TR>"
      Loop
      Response.Write "</TABLE>"
   End Sub
   Sub ShowNavBar(rst)
   Dim iPageCount
   Dim iLoop
   Dim sScriptName
      'This version provides richer user navigation but
      'relies on RecordCount and PageCount, which negate
      'the benefits of specifying a CacheSize for a
      'Server-side cursor.
      Response.Write "<BR><BR>"
      sScriptName = Request.ServerVariables("SCRIPT_NAME")
      If iPageNum > 1 Then
         Response.Write " <a href=" & sScriptName & "?iPageNum="
         Response.Write (iPageNum -1) & "><< Previous</a>"
      End If
      iPageCount = rst.PageCount
      Do Until iLoop > iPageCount
         If iLoop = iPageNum Then
            Response.Write " <B>" & CStr(iLoop) & "</B>"
         Else
            Response.Write " <a href=" & sScriptName & "?iPageNum=" & _
            Cstr(iLoop) & ">" & iLoop & "</a>"
         End If
         iLoop = iLoop + 1
      Loop
      If Not rst.EOF Then
         Response.Write " <a href=" & sScriptName & "?iPageNum="
         Response.Write (iPageNum +1) & "> Next >></a><BR>"
      Else
         Response.Write "<BR>"
      End If
      Response.Write "Page " & iPageNum & " of " & iPageCount & "<BR>"
      Response.Write rst.RecordCount & " Records"
   End Sub
   Sub ShowFastNavBar(rst)
   Dim iPageCount
   Dim iLoop
   Dim sScriptName
      'This method is very efficient when specifying a CacheSize
      'and using a Server-side cursor, because it does not
      'use RecordCount and PageCount. User experience is sacrificed.
      Response.Write "<BR><BR>"
      sScriptName = Request.ServerVariables("SCRIPT_NAME")
      If iPageNum > 1 Then
         Response.Write " <a href=" & sScriptName & "?iPageNum="
         Response.Write (iPageNum -1) & "><< Previous</a>"
      End If
      If Not rst.EOF Then
         Response.Write " <a href=" & sScriptName & "?iPageNum="
         Response.Write (iPageNum +1) & "> Next >></a><BR>"
      Else
         Response.Write "<BR>"
      End If
      Response.Write "Page " & iPageNum
   End Sub
   Sub CleanUp(rst)
      If Not rst Is Nothing then
         If rst.state = adStateOpen then rst.close
         set rst = nothing
      End If
   End Sub
</SCRIPT>