Solved

Recordset paging like Google

Posted on 2003-10-28
10
709 Views
Last Modified: 2012-06-21
I am using recordset paging to display a link for each page of records returned from my query.

I am aiming for something like this:

<Previous> | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | <More>

So far, I can create a link for each page but how can I display only 10 at a time with the Previous and More links?

' Loop through the number of pages writing a link for each
Dim x, lb, ub

For x=1 To numpages
  ' lb is the lowest record number on that page, ub is the highest
        lb = (x-1) * pagesize + 1
        ub = x * pagesize
  ' Makes sure the final link doesn't extend past the number of records
        If ub > numrecs Then ub = numrecs
  ' Don't display the current page as a hyperlink
        If x <> mypage Then       
          ' Example output: <A HREF=paging.asp?page=4;recs=25>4</A>
                Response.Write("<font face=Verdana size=2><a href=select.asp?page=" & x & "&recs=" & pagesize & "&date_from="&date_from&"&date_to="&date_to&">" & x & "</a></font>")
        Else
          ' The active page
                Response.Write "<font face=Verdana size=2><b>" &(x)& "</b></font>"
        End If
  ' Writes | as a separator if we're not at the last link
        If x <> numpages Then Response.Write(" | ")
Next

Thanks!
0
Comment
Question by:yourbudweiser
  • 5
  • 4
10 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 9633686
0
 
LVL 3

Expert Comment

by:sicknote
ID: 9633766
for the next page last page section of the links:

Response.Write("<font face=Verdana size=2><a href=select.asp?page=" & (mypage - 1) & "&recs=" & pagesize & &date_from="&date_from&"&date_to="&date_to&">back</a></font>")

Response.Write("<font face=Verdana size=2><a href=select.asp?page=" & (mypage + 1) & "&recs=" & pagesize & &date_from="&date_from&"&date_to="&date_to&">next</a></font>")

for the maximum of 10 pages either way, use:

dim iStartPage, iEndPage

iStartPage = 1
if mypage > 11 then iStartPage = mypage - 10

iEndPage = mypage + 10
if iEndPage > numpages then iEndPage = numpages

For x=iStartPage To iEndPage
  'use your existing code here
Next

----
hopefully that all mates sense...
0
 
LVL 3

Author Comment

by:yourbudweiser
ID: 9633894
sicknote, I only want to display 10 links at any given time. When I click the back or next links, as in your code above, it just adds another page link to the ones already displayed.

Garyc, I am still looking over your suggestion.
0
 
LVL 58

Expert Comment

by:Gary
ID: 9633983
You should just be able to take the sub PageNavigation code and add it to yours with very little or no change
0
 
LVL 3

Author Comment

by:yourbudweiser
ID: 9634040
Gary, could you please redo and plug in my variables?

sub PageNavigation(script, page, total_page, count, total_count)
if total_page > 1 then
response.write "<center>Page "
page=int(page)
clickedpage=page

    if page>1 and total_page>count then
         temppage=page-count
         if temppage<1 then temppage=1
         if temppage>total_page-count then temppage=total_page-count
         response.write "<a href='" & script & "?page=" & temppage & "'><<<</a>&nbsp; | "
   end if
   
    temppage=page
    if temppage>total_page-count then temppage=total_page-(count-1)
    for a = temppage to (page+(count-1))
      if a<=total_page then
                 if a=clickedpage then
                      response.write " <b>" & a & "</b>&nbsp; | "
                else
                     response.write "<a href='" & script & "?page=" & a & "'>" & a & "</a> |&nbsp; "
                end if
      end if
    next
      if page<total_page-count then response.write "<a href='" & script & "?page=" & a & "'>&nbsp;>>></a>"

response.write  " of &nbsp;" & total_page & " Page/s"
response.write "</center>"

end if
end sub


  If Not rs.EOF Then
       call PageNavigation(script, page, rs.PageCount, num_row, rs.recordcount)
  else
       response.write "No Searches"
  End If
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 58

Accepted Solution

by:
Gary earned 100 total points
ID: 9634135
All you need to do is amend the few lines below to your required number of pages to display and number of records to show and also the name of your recordset e.g. in this example I use RS

<%
If Not rs.EOF Then
      page=request("page") ' This is passed thru the querystring, if nothing then defaults to 1
      total_page = rs.PageCount ' Passed directly from the recordset
      total_count = rs.recordcount ' Passed directly from the recordset, how many records we have in total
      count = 10 ' Number of pages to show in the navigation
      recs = 25 ' Number of records to show
      
    call PageNavigation(page, total_page, count, total_count, recs)
else
    response.write "No Searches"
End If



sub PageNavigation(page, total_page, count, total_count, recs)
if total_page > 1 then
response.write "<center>Page "
page=int(page)
clickedpage=page

    if page>1 and total_page>count then
         temppage=page-count
         if temppage<1 then temppage=1
         if temppage>total_page-count then temppage=total_page-count
         response.write "<a href='select?page=" & temppage & "&recs=" & recs & "'><<<</a>&nbsp; | "
   end if
   
    temppage=page
    if temppage>total_page-count then temppage=total_page-(count-1)
    for a = temppage to (page+(count-1))
      if a<=total_page then
                 if a=clickedpage then
                      response.write " <b>" & a & "</b>&nbsp; | "
                else
                     response.write "<a href='select?page=" & a & "&recs=" & recs & "'>" & a & "</a> |&nbsp; "
                end if
      end if
    next
      if page<total_page-count then response.write "<a href='select?page=" & a & "&recs=" & recs & "'>&nbsp;>>></a>"

response.write  " of &nbsp;" & total_page & " Page/s"
response.write "</center>"

end if
end sub

%>
0
 
LVL 3

Author Comment

by:yourbudweiser
ID: 9634169
Thanks for the time and effort!

YourBudWeiser
0
 
LVL 3

Author Comment

by:yourbudweiser
ID: 9634954
The final code works great but in certain circumstances I am getting negative page numbers.

-7|-6|-5|-4|-3|-2|-1|0|1|2|

Sub PageNavigation(page, total_page, count, total_count)
      If total_page > 1 Then
            page=int(page)
            clickedpage=page

          If page>1 and total_page>count Then
              temppage=page-count
              if temppage<1 then temppage=1
              if temppage>total_page-count then temppage=total_page-count
              ' Show Previous Link
              response.write "<font face=Verdana size=2><a href='select.asp?page="&temppage&"&date_from="&date_from&"&date_to="&date_to&"'><< </a>|</font>"
               End If
   
          temppage=page
          If temppage>total_page-count Then temppage=total_page-(count-1)
          For a = temppage to (page+(count-1))
                  If a<=total_page Then
                    If a=clickedpage then
                          ' Current Page
                        response.write "<font face=Verdana size=2><b>"&a&"</b>|</font>"
                      Else
                            ' Linked Page
                         response.write "<font face=Verdana size=2><a href='select.asp?page="&a&"&date_from="&date_from&"&date_to="&date_to&"'>"&a&"</a>|</font>"
                 End If
                  End If
            Next
            ' Show Next Link
               If page<total_page-count Then Response.Write "<font face=Verdana size=2><a href='select.asp?page="&a&"&date_from="&date_from&"&date_to="&date_to&"'> >></a></font>"

'      Response.Write  " of &nbsp;" & total_page & " Page/s"
      end if
End Sub      
0
 
LVL 58

Expert Comment

by:Gary
ID: 9635327
Slight amendment

Sub PageNavigation(page, total_page, count, total_count)
     If total_page > 1 Then
          page=int(page)
          clickedpage=page

         If page>1 and total_page>count Then
             temppage=page-count
             if temppage<1 then temppage=1
             if temppage>total_page-count then temppage=total_page-count
             response.write "<font face=Verdana size=2><a href='select.asp?page="&temppage&"&date_from="&date_from&"&date_to="&date_to&"'><< </a>|</font>"
         End If
   
         temppage=page
         If temppage>total_page-count Then temppage=total_page-(count-1)
         if temppage<1 then temppage=1
         For a = temppage to (page+(count-1))
               If a<=total_page Then
                  If a=clickedpage then
                      response.write "<font face=Verdana size=2><b>"& a &"</b>|</font>"
                     Else
                        response.write "<font face=Verdana size=2><a href='select.asp?page="&a&"&date_from="&date_from&"&date_to="&date_to&"'>"&a&"</a>|</font>"
                  End If
               End If
          Next
             If page<total_page-count Then Response.Write "<font face=Verdana size=2><a href='select.asp?page="&a&"&date_from="&date_from&"&date_to="&date_to&"'> >></a></font>"

     end if
End Sub
0
 
LVL 3

Author Comment

by:yourbudweiser
ID: 9635403
Thanks alot GaryC123!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 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

15 Experts available now in Live!

Get 1:1 Help Now