ASP Classic - Auto-Numbering and Paging

Posted on 2014-02-02
Medium Priority
Last Modified: 2014-02-08
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?
Question by:Wayne Barron
  • 5
  • 3
LVL 58

Expert Comment

ID: 39827963
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
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 39828046
CarrzKiss, this is an old time article about page numbering using getrows. http://www.4guysfromrolla.com/webtech/070500-1.shtml

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

LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 39828090
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

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

LVL 31

Author Comment

by:Wayne Barron
ID: 39828609
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.


LVL 31

Author Comment

by:Wayne Barron
ID: 39828646
Fixed INC file, inside of folder.
Download is good now, and fully working.

LVL 31

Author Comment

by:Wayne Barron
ID: 39830491
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
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 39830599
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 http://datatables.net/.  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!
LVL 31

Accepted Solution

Wayne Barron earned 0 total points
ID: 39831183
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.
LVL 31

Author Closing Comment

by:Wayne Barron
ID: 39843924
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.


Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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.

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question