arrghh brain has given up on me

Associate
Joined
8 Oct 2005
Posts
97
Location
Bristol
This to me seems like it should be realy simple, but for the life of me i cant figure it out

im paging through a mysql recordset using ASP quite happily but i just want to show some totals at the top of the page

example

9 products in a category max of 6 per page

should say at the top of page 1 "showing products 1 to 6 of 9"
and page 2 should say "showing products 7 to 9 of 9"

i cant figure out how i can get the second value !!

ive got these variables to use
PageSize
PageCount
RecordCount
CurrentPage

my brain hasnt woken up yet, it should be realy simple but i just cant see it

if anyone has a brain that works and can show me what the heck i need to do it would be much appreciated

please note posting of php code could lead to a nervous breakdown pseudo will do
 
ClearChaos said:
This to me seems like it should be realy simple, but for the life of me i cant figure it out

im paging through a mysql recordset using ASP quite happily but i just want to show some totals at the top of the page

example

9 products in a category max of 6 per page

should say at the top of page 1 "showing products 1 to 6 of 9"
and page 2 should say "showing products 7 to 9 of 9"

i cant figure out how i can get the second value !!

ive got these variables to use
PageSize
PageCount
RecordCount
CurrentPage

my brain hasnt woken up yet, it should be realy simple but i just cant see it

if anyone has a brain that works and can show me what the heck i need to do it would be much appreciated

please note posting of php code could lead to a nervous breakdown pseudo will do

Couldn't you do a loop to begin with maintaining your own count of the current page, then once complete use that count as the total and start again. i.e

Code:
number_of_recs = 0
while not at end of recordset
   number_of_recs++
end while

total_recs = number_of_recs

string = current_prod" of "total_recs

There's probably much easier ways of doing this, infact I wouldn't be surprised if there's an attribute of the recordset object which will give you the number of records.
 
PageSize
PageCount
RecordCount
CurrentPage

The first Record on the page would be
(Pagesize * CurrentPage) - (PageSize-1)
Page 1: (6 * 1) - (6-1) = 1
Page 2: (6 * 2) - (6-1) = 7
Page 3: (6 * 3) - (6-1) = 13

The last Record on the page is easy
First result + PageSize
Page 1: 1 + 5 = 6
Page 2: 7 + 5 = 12
Page 3: 13 + 5 = 18

The total record count you already have this information - so the script would look something like this:

Dim iFirstRecord, iLastRecord

iFirstRecord = (Pagesize * CurrentPage) - (PageSize-1)
iLastRecord = iFirstRecord + PageSize

Response.write iFirstRecord & " to " & iLastRecord & " of " & RecordCount

Hope this helps.
 
Just reread your post and you probably need to check to see if the count on the last page is past your total records - so you want something like this.

Dim iFirstRecord, iLastRecord

iFirstRecord = (Pagesize * CurrentPage) - (PageSize-1)
iLastRecord = iFirstRecord + PageSize

if iLastRecord > RecordCount then iLastRecord = RecordCount

Response.write iFirstRecord & " to " & iLastRecord & " of " & RecordCount
 
hehe no worries I know how it feels when you have been staring at the same bit of code for ages thinking to yourself that it has to be simple lol yet you can never seem to figure it out lol - best thing is to leave it and revisit it later ;)
 
Back
Top Bottom