Solved

Recordset paging like Google

Posted on 2003-10-28
10
714 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
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/…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 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