• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1707
  • Last Modified:

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
else
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.


Pages.
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?
Carrzkiss
0
Wayne Barron
Asked:
Wayne Barron
  • 5
  • 3
1 Solution
 
GaryCommented:
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
0
 
Scott Fell, EE MVEDeveloperCommented:
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
     aResults=rs.getrows()
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
  Else
    iStop = iRows
  End If

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

0
 
Scott Fell, EE MVEDeveloperCommented:
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
     else
     prevPage = 1
end if
nextPage=cdbl(page)+1

' 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

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

NOTES:

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.

Download
http://www.cffcs.com/Tutorials/paging_AutoNumber.zip

Thanks
Carrzkiss
0
 
Wayne BarronAuthor Commented:
Fixed INC file, inside of folder.
Download is good now, and fully working.

http://www.cffcs.com/Tutorials/paging_AutoNumber.zip
0
 
Wayne BarronAuthor 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...


So.
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
Carrzkiss
0
 
Scott Fell, EE MVEDeveloperCommented:
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!
0
 
Wayne BarronAuthor 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)
Else
ctRec = rs("comID")+1  '(this adds 1 to the existing count)
end if

I like it.
Works great for what I need it for.
0
 
Wayne BarronAuthor 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.


Wayne
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now