This content is not currently approved and is visible here for review only.

Library code snippets

Improvements to the "Paginate a recordset" Post by James Crowley

Search Results indexing across multiple pages

Hi Guys

This code i really simple but you have to know how request.querystrings work.

 

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%' you need to include your database mappath location%>
<!--#Include file="cn.asp"-->

<%
'create a recordset object
Set rItems = Server.CreateObject("ADODB.Recordset")

'set the cursor location and type
rItems.CursorLocation = 3' adUseClient
rItems.CursorType = 3 'adOpenStatic

'number of rows to cache at a time. Should be set to the same as PageSize
rItems.CacheSize = 10

'number of items to display per 'page'
rItems.PageSize = 10

 dim rs
 dim cn
 
 set cn = Server.CreateObject("Adodb.Connection")
 cn.Open conn
 sqlstring = "Select * From staffnames" 'change this to suit your db
 rItems.open sqlstring, cn

'check if empty
If rItems.EOF Then
    'no rows
Else

    'set current page
if request.QueryString("page") <> "" then ' if page= nothing this you are on the first page without this if statement you would get an error like Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
    rItems.AbsolutePage = Request.QueryString("page")
end if
    'get the total number of records
    nItemCount = rItems.RecordCount

    'get the number of pages
    nPageCount = rItems.PageCount

    'loop through an display the items in the recordset
    Do While Not rItems.EOF and nItem < rItems.PageSize
  'displays records
  response.write rItems.fields("Name")
  %><br /><%

        'do something
        rItems.MoveNext 'move to the next record
        nItem=nItem+1 'increment count

    Loop
End If

'close the recordset
rItems.Close

'and destroy the object...
Set rItems = Nothing


%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>


<p>&nbsp;</p>
<p>
<%
' this loop works out the amount of pages needed and then writes them in html
dim i
i = 1
for i =1 to nPageCount%>
<a href="default2.asp?page=<%=i%>"><%=i%></a>
<%
next
%>

</p>
</body>
</html>

if you need help let me know.

Good luck!

Comments

  1. 01 Jan 1999 at 00:00

Leave a comment

Sign in or Join us (it's free).

AddThis

Related podcasts

  • ASP.NET Caching and Performance

    Steve Smith, owner of ASP Alliance and Lake Quincy Media joins us today to teach us about some hidden gems in ASP.NET caching and performance. Steve’s expertise in this area comes from first-hand experience as Lake Quincy’s ad system serves over 60 requests per second and handles over 150 million...

Related jobs