Dividing search results in sets of 30 with ASP

They have: 27 posts

Joined: Aug 2001

I would like to setup a query and display at most 30 results per page using ASP. Could anyone tell me what the best method would be to carry this out? I was thinking of passing a lot of parameters in the url to tell how many results to show.

Thanks,

Mark

They have: 27 posts

Joined: Aug 2001

Just thought I would mention, I'm ok on queries. I just need advice on how to display 30 results/page.

Thanks,

Mark

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

Been a while since I've used ASP, but I remember searching MSDN for code to do just that. Check out these URLs...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnproasp2/html/apagedresultsetexample.asp?frame=true
http://msdn.microsoft.com/library/psdk/indexsrv/ixuwebqy_1mxx.htm
http://msdn.microsoft.com/library/default.asp?URL=/library/wcedoc/adoce31/ado30ref_6.htm

basic concept.....
Quickie Code [untested]

<%
'Create SQL query
Query = "SELECT * FROM table_name"

'Create a connection object to execute the query
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "provider=msidxs"
objConn.Open
Set objRS = Server.CreateObject("ADODB.RecordSet")
objRS.Open Query, objConn, adOpenKeyset,adLockReadOnly
If objRS.EOF Then
    Response.Write("No records found!")
    Set objRS = Nothing
    objConn.Close
    Set objConn = Nothing
    Response.End
End If

...

'Set the page number - each page holds five records
RowCount = 5
objRS.PageSize = RowCount

'Jump to the page you want to view
Page = Request.Form("Page")
objRS.AbsolutePage = Page

'Now print your stuff...
Do While Not objRS.EOF And RowCount > 0
    'BLAH!!
    RowCount = RowCount - 1
    objRS.MoveNext
Loop

'Clean up
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>
'
Boy was it hard to write that! I kept wanting to put semicolons on the end of the lines. lol!

Mark Hensler
If there is no answer on Google, then there is no question.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.