Solved

ASP Classic - Auto-Numbering and Paging

Posted on 2014-02-02
9
1,310 Views
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
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
Comment
Question by:Wayne Barron
  • 5
  • 3
9 Comments
 
LVL 58

Expert Comment

by:Gary
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
0
 
LVL 52

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
     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
 
LVL 52

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
     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
 
LVL 30

Author Comment

by:Wayne Barron
ID: 39828609
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 30

Author Comment

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

http://www.cffcs.com/Tutorials/paging_AutoNumber.zip
0
 
LVL 30

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


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
 
LVL 52

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!
0
 
LVL 30

Accepted Solution

by:
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)
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
 
LVL 30

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.


Wayne
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SELECT TOP 5 COUNT(*)  adding/changing some varibales 14 49
post data with a link 8 49
Round to 2 decimal places 2 36
Select distinct 25 61
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 would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now