Posted By

krisdb on 05/14/07


Tagged

ASP


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

gafsveno
remix4
asifrizvigmailcom


pagination row_number()


 / Published in: ASP
 

  1. dim iContentPerPage : iContentPerPage = 4
  2. dim iTotalRecords: iTotalRecords = request.querystring("total")
  3. dim iStart: iStart = request.querystring("start")
  4. dim sAlpha: sAlpha = request.querystring("a")
  5.  
  6. dim iEnd,iTotalRecords
  7.  
  8. 'get total records
  9. if ((len(iTotalRecords) = 0) or (not isnumeric(iTotalRecords))) then
  10. strsql = "select count(id) FROM [TABLE] " & sqlEx
  11. itemArray = selectDatabase(strsql)
  12. iTotalRecords = itemArray(0,0)
  13. end if
  14.  
  15. 'set the starting position, either zero or from the query string
  16. if (len(iStart) = 0) then
  17. iStart = 1
  18. else
  19. iStart = Cint(iStart)
  20. end if
  21.  
  22. 'set the end position
  23. 'if the number of items per page plus the starting position is less than the total,
  24. 'then show the number of items added to the starting position
  25. 'otherwise we are at the end
  26. If (cint(iTotalRecords) >= (iContentPerPage + iStart)) Then
  27. iEnd = iContentPerPage + iStart-1
  28. Else
  29. iEnd = iTotalRecords
  30. End If
  31.  
  32. if (len(sAlpha) > 0) then _
  33. sqlEx = "WHERE substring([FIELD],1,1) = '" & sAlpha & "' "
  34.  
  35. strsql = "select member_id,uniqueid,screenname from " &_
  36. "(SELECT ROW_NUMBER() OVER (order by screenname asc) AS Row, row_id FROM [TABLE] "&sqlEx&") AS LogWithRowNumbers " &_
  37. "WHERE Row >= "&iStart&" AND Row <= "&iEnd
  38.  
  39. itemArray = selectDatabase(strsql)
  40.  
  41. 'display results
  42. if isArray(itemArray) then
  43. for introw = 0 to ubound(itemArray,2)
  44. id = itemArray(0,introw)
  45. next
  46. end if
  47.  
  48. response.write "<br /><table border=""0"" width=""95%"" cellpadding=""2"" cellspacing=""0"" align=""center""><tr>"
  49.  
  50. 'check whether to show the previous link or not
  51. if (iStart > iContentPerPage) then
  52. response.write "<td style=""width:33%;"" align=""left""><a href="""&scriptName&"?start="&(iStart-iContentPerPage)&"&total="&iTotalRecords&""" style=""text-decoration:none;""><< PREVIOUS PAGE</a></td>"
  53. else
  54. response.write "<td style=""width:33%;""> </td>"
  55. end if
  56.  
  57. response.write "<td style=""width:33%;"" align=""center"">" & (iEnd) & " of " & (iTotalRecords) & "</td>"
  58.  
  59. 'check whether to show the next link or not
  60. if (cint(iEnd) < cint(iTotalRecords)) then
  61. response.write "<td style=""width:33%;"" align=""right""><a href="""&scriptName&"?start="&(iEnd+1)&"&total="&iTotalRecords&""" style=""text-decoration:none;"">NEXT PAGE >></a></td>"
  62. else
  63. response.write "<td style=""width:33%;""> </td>"
  64. end if

Report this snippet  

You need to login to post a comment.