ASP Classic - Auto-Numbering and Paging

Hello All

OK, I have a paging system, that using Auto-Numbering.

k = 1
k = k + 1

This is the code that I am using

getPage = Request.QueryString("page")
k = 1
if getPage<>"" then
if getPage=1 then
k = 1
k = getPage +9
end if
end if

Open in new window

Everything works great, until I get to the 3rd page, once I get there, it does not count properly.

This is what I am needing.

1,2,3,4,5,6,7,8,9,10, exc...

Then numbering the records
1-10 = Page 1
11-20 = Page 2
20-30 = Page 3
30-40 = Page 4

You get the point.

To answer you question.
I am using the Database ID# in another section of the page.
However, the Auto Numbering, is used to display an actual 1,2,3,4,count, instead of showing.
200, 201, 202.
When the page just loads, as people are more prone to understand the display of records using the starting of numbers, instead of the ID which can start anywhere, which will make the person wonder if they missed some records or not.

Any idea's on this one?
LVL 31
Wayne BarronAuthor, Web DeveloperAsked:
Who is Participating?
Wayne BarronConnect With a Mentor Author, Web DeveloperAuthor Commented:
Thanks Scott.
I like that link, however, I am not sure that it would suite the site that I am doing right now. However it might work in the admin section, for dealing with Users and so forth.

I just added in the code that I posted above, and it worked great.
Just tested it, and it took 2 minutes to do the code, and to test.
What it does is the following.

When you post.
It counts the records that exist in the database
If rs.eof then
ctRec = 1 '(This will be the first recorded created)
ctRec = rs("comID")+1  '(this adds 1 to the existing count)
end if

I like it.
Works great for what I need it for.
If you are displaying the page number (1,2,3 etc) then why are you adding 9 to the page number
k = getPage +9
Think you best post your db code/sql explaining how you are selecting records
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
CarrzKiss, this is an old time article about page numbering using getrows.

First, using getrows is a lot faster to process

if not rs.bof or not rs.eof then
end if
' close your connections here

Dim iRows, iCols, iRowLoop, iColLoop, iStop
  iRows = UBound(aResults, 2)
  iCols = UBound(aResults, 1)

  If iRows > (iOffset + iStart) Then
    iStop = iOffset + iStart - 1
    iStop = iRows
  End If

  For iRowLoop = iStart to iStop
    For iColLoop = 0 to iCols
      Response.Write aResults(iColLoop, iRowLoop) & " "
    Response.Write "<BR>"
'///// in the body stection
 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

Open in new window

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Using your current code
dim k, startingRecord
page = 1
startingRecord = 200
if  Request.QueryString("page")<>"" then
     if isnumeric(Request.QueryString("page")) then
          page = Request.QueryString("page")
    end if
end if
startingRecord = (10 * cdbl(page)-1)+1
endingRecord = cdbl(startingRecord) + 10
' sql = "select ID, one,two, three from MyTable where ID >= "&startingRecord&" ID <= "& endingRecord
' to test try response.write sql

if cdbl(page) > 1 then
     prevPage = cdbl(Page)-1
     prevPage = 1
end if

' in the body section

     response.write <a href=""?page="&prevPave&"""><< Prev </a>&nbs;"
     response.write <a href=""?page="&nextPave&""">>> Next </a>"

Open in new window

Wayne BarronAuthor, Web DeveloperAuthor Commented:
OK guys.
I made up a demo using the paging system that I am using.


Line 103 - 111
These are the lines that generate the Numbers.
(Looking at the demo when run, you will see 2 numbers.
The numbers in the parentheses, Are the Auto-Numbers.
These are the numbers that need to be in order from page to page.
NOW, is this demo, the Database Numbers, are in order.
So please IGNORE them, as we are not concerned with them.)

You should understand it once you look at it.


Wayne BarronAuthor, Web DeveloperAuthor Commented:
Fixed INC file, inside of folder.
Download is good now, and fully working.
Wayne BarronAuthor, Web DeveloperAuthor Commented:
Hello All;
I am going about this wrong!

What I am going to do instead, is the following:

When a new record is inserted, Look at the last record (IF EXIST)
And do the following.

ComID = 3 (Say there is 3 records)

update tablename set comid=ComID+1

Then I can use the ComID number, as the Com # that the visitors see, instead of the actual number.
This way, each new Com will have a unique ID for that Category.
And then all records will be able to display with the 1,2 ,3, 4 exc...

I am going to close this one down.
Thanks for the suggestions of the Paging scripts and so forth, however, they did not help or assist in what I was trying to do. As shown in the Demo Code that I supplied.

Take care
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Wayne, I have been overwhelmed with my own programming over the weekend to look at your updated code.

It does sound like this may be more complex than it needs to be.  I have used that core code from 4guys in the past and it works nicely although I had to change my own thinking on how I was doing this in the past.  That method is very fast.

Another option if you are displaying rows of data is to use javascript. I use  Using the same getrows via ajax, I will spit out about 100 rows of data pretty quickly.  When the user gets towards the end, use ajax to build on the array that is already in the browser with another 100 rows of data.  Then the user can sort, search and page as desired without more calls to the server.

It sounds like you have a good handle on this for your own needs.

Best of luck!
Wayne BarronAuthor, Web DeveloperAuthor Commented:
What I proovided is what I did, in order to get it to work for what I needed it to do.
It is quick and easy to implement, and the things rocks.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.