Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - getting a specific number of records
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

getting a specific number of records

 Post Reply Post Reply
Author
portaloo View Drop Down
Newbie
Newbie


Joined: 07 June 2002
Location: New Zealand
Status: Offline
Points: 12
Post Options Post Options   Thanks (0) Thanks(0)   Quote portaloo Quote  Post ReplyReply Direct Link To This Post Topic: getting a specific number of records
    Posted: 29 September 2003 at 3:00am
What I'm trying to do is get a specific number of records from a large db.

I know i can use getrows and other methods which will speed up access but what I am wondering is if it is possible to select a number of records.

ie on page 1 select records from 1 to 25, on page 2 select records 26 to 50 etc etc until the last record is displayed.

My thinking is this, if I've got 700 records why waste the time and resources getting the last page by retrieving the first 675 records when they aren't even going to be used. I think that by doing something like this I can speed things up more.

Another question - am I just being silly about this, will there be any time/resource savings at all?

Cheers

portaloo


Edited by portaloo
Back to Top
b_bonnett View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Location: New Zealand
Status: Offline
Points: 275
Post Options Post Options   Thanks (0) Thanks(0)   Quote b_bonnett Quote  Post ReplyReply Direct Link To This Post Posted: 29 September 2003 at 3:15am

Take a look over http://www.devguru.com/Technologies/ado/quickref/recordset.h tml. The parts you are interested in are PageSize, AbsolutePage, PageCount and LockType.

There is also a good tutorial at http://www.asp101.com/samples/viewasp.asp?file=db%5Fpaging%2 Easp.

Hope this helps,
Blair

Webmaster, The Plane Gallery
Greetings From Christchurch
Back to Top
portaloo View Drop Down
Newbie
Newbie


Joined: 07 June 2002
Location: New Zealand
Status: Offline
Points: 12
Post Options Post Options   Thanks (0) Thanks(0)   Quote portaloo Quote  Post ReplyReply Direct Link To This Post Posted: 29 September 2003 at 4:31am
yo Blair right back at ya from chch too
Back to Top
3BEPb View Drop Down
Groupie
Groupie


Joined: 07 August 2003
Location: United States
Status: Offline
Points: 81
Post Options Post Options   Thanks (0) Thanks(0)   Quote 3BEPb Quote  Post ReplyReply Direct Link To This Post Posted: 30 September 2003 at 9:20pm

AFAIK this is paging thru recordset. Let me write simple one for you:

<%
Const intPageSize = 10 'this is number of records on one page
Dim intCurrentPage, strQ
Dim intTotalPages, I

If Request("Page") = "" Then
   intCurrentPage = 1
Else
   intCurrentPage = CInt(Request("Page"))
End If

dim objConn, RS, AppDatabase, SQL, totRec, RS2, totRec2, Author, Blurb, Title, Story, sLad

Set objConn = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.RecordSet")
RS.Cursorlocation = adUseClient
RS.CursorType = adOpenStatic
RS.PageSize = intPageSize
AppDatabase="Driver={SQL Server};DSN=;Server=112.112.112.112;UID=userID;PWD=password"
objConn.Open AppDatabase
Set RS.ActiveConnection=objConn

RS.Open "SELECT * FROM your_table"

If Not(RS.EOF) Then RS.AbsolutePage = intCurrentPage

intTotalPages = RS.PageCount
totRec=RS.RecordCount
If totRec = 0 Then
response.write "No records available"
Else

I=0
do until I = RS.PageSize
 I=I+1

response.write RS("Something")

 RS.MoveNext
 If RS.EOF Then Exit do
loop
RS.Close
objConn.Close
End If
If intCurrentPage > 1 Then %><a href="<%= Request.ServerVariables("SCRIPT_NAME")%>?Page=<%= (intCurrentPage-1)%>">
                   <b>back</b></a> |<%End If%>Page <%=intCurrentPage%> 
                    out of <%=intTotalPages%> | <%If totRec <> 0 Then
    If intCurrentPage <> intTotalPages Then%>| <a href="<%= Request.ServerVariables("SCRIPT_NAME")%>?Page=<%= (intCurrentPage+1)%>><b>forward</b></a& gt; 
                   <%
  End If
End If
%>

Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 01 October 2003 at 12:58am

You can do:

SELECT TOP int *

Back to Top
b_bonnett View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Location: New Zealand
Status: Offline
Points: 275
Post Options Post Options   Thanks (0) Thanks(0)   Quote b_bonnett Quote  Post ReplyReply Direct Link To This Post Posted: 01 October 2003 at 4:32am

One thing I'd add to the code 3BEPb gave you is to check the number of pages, then make sure the user is not trying to view a page out of the limits, then set the page we are viewing within the recordset.

Blair

Webmaster, The Plane Gallery
Greetings From Christchurch
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.