I have an dreaweaver-built ASP page that displays the results of an access DB via the recordset derived from a DB query. My asp page has buttons that sort (via URL params) the Access DB results by column name - using order by ASC or DESC. I page through the recordset at 15 records per page.
They way the numeric paging works now is that when the next/previous page is clicked on there's a variable called offset that gets appended to the URL that changes with the page #. For instance, when the page first loads (page 1) the offset is 0. For the next page (page 2) with the next set of records, the offset is 15, the next page offset is 30 (in line with the 15 results per page setup) and so forth.
When a user sorts the results of the DB by the column "company", for instance, they have keep paging thru the recordset to get to a company beginning with a certain letter. Even though the results can be sorted ASC or DESC, a user still has to keep flipping thru the pages to get to a company whose name begins with say letter "J". What I'd like to do is create an alphabetical index at the bottom of the ASP page, underneath the numeric page numbers, that allows users to click on a given letter (e.g. "J") and have them taken to the section of the recordset with companies that begin with letter "J"
This way I I have the offset/page jumping to wherever wherever it is in the recordset that the company starts with "J" or whatever letter has been clicked on. The offset for letter "J" is offset 201 (page 14) - which displays the results for companies that begin with J and whatever else follows in the recordset. The user can then keep paging thru the recordset numerically (using the pages) if they choose to, to see the next set of records - any left-over Js & K's and beyond.
Hardcoding the offsets to the letters would not be very feasible in the long-run b/c if new records are added, the offsets will surely change, and will no longer be accurate. Is there any way to programmatically assign a letter to an offset/page #, such that when the letter is clicked on, the user can "jump" to the section of the recordset where the records begin with the clicked on letter?
Any assistance with this (esp with examples) will greatly be appreciated!
I've included the numeric paging code (a dreamweaver extension by tom muck) which might be useful in helping to see how the paging (and use of offset) works:
VARIABLES USED IN THE CODE:
MM_Size = rsProposals_numRows
rsProposals_numRows = rsProposals_numRows + Repeat1_numRows
Repeat1_numRows = 15 'i.e. 15 records per page
MM_keepMove basically keeps track of what URL parameters are to be maintained - in this case the DB column to be sorted by and the direction of sort - ASC or DESC
Note: 9 pages are displayed at a go - i.e. one can choose to view/browse the results of up to 9 pages at a go
'This section shows/navigates back to the Previous 9 pages
<%
If MM_offset > MM_size * 9 Or MM_offset/MM_size - int(9/2) > 0 Then
TFM_Previous = MM_offset - 10 * MM_size
If TFM_Previous < 0 then TFM_Previous = 0
Response.Write(".<a href=""" & Request.ServerVariables("U
RL") & "?" & MM_keepMove & "offset=" & TFM_Previous & """>")
Response.Write("Previous " & "9" & " pages</a> ")
End If
%>
''This section shows the current 9 pages a viewer can click on to view results for : i.e. e.g. -> 10 11 12 13 14 15 16 17 18
<%
TFM_MiddlePages = 9 ' # of pages to be displayed at a time
TFM_delimiter = " " ' a space separates the page #s
TFM_startLink = MM_offset + 1 - MM_size * (int(TFM_middlePages/2))
If MM_offset > 0 Then TFM_LimitPageEndCount = int(TFM_startLink/MM_size)
If TFM_startLink < 1 Then
TFM_startLink = 1
TFM_LimitPageEndCount = 0
End If
TFM_endLink = MM_size * TFM_MiddlePages + TFM_startLink - 1
If TFM_endLink > rsProposals_total Then TFM_endLink = rsProposals_total
For i = TFM_startLink to TFM_endLink Step MM_size
TFM_LimitPageEndCount = TFM_LimitPageEndCount + 1
if i <> MM_offset + 1 Then
Response.Write("<a href=""" & Request.ServerVariables("U
RL") & "?" & MM_keepMove & "offset=" & i-1 & """>")
Response.Write(TFM_LimitPa
geEndCount
& "</a>")
else
Response.Write("<font color='#FF0000'> ") ' change color of currently displayed page (which is now unclickable)
Response.Write(TFM_LimitPa
geEndCount
& "</font> ")
End if
if(i <= TFM_endLink - MM_size) then Response.Write(TFM_delimit
er)
Next
%>
'This section shows/navigates to the Next 9 pages
<%
If MM_offset < rsProposals_total - MM_size * 9 Then
Response.Write(" <a href=""" & Request.ServerVariables("U
RL") & "?" & MM_keepMove & "offset=" & (MM_offset + 9*MM_size) & """>")
Response.Write("Next " & "9" & " of " & rsProposals_TFMtotalPages & " pages</a> ")
End If
%>
The actual paging text displayed on the ASP page looks something like:
1 2 3 4 5 6 7 8 9 Next 9 of 26 pages ' for offset = 0 -> 1 is colored red (#FF0000) and is unclickable
.Previous 9 pages 3 4 5 6 7 8 9 10 11 Next 9 of 26 pages ' for offset = 90 -> 7 is colored red and unclickable now
.Previous 9 pages 21 22 23 24 25 26 ' for offset = 375 - the last of the records in the recordset -> 26 is red & unclickable
Hope this helps!