Solved

Recordset paging like Google

Posted on 2003-10-28
10
704 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

759 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

20 Experts available now in Live!

Get 1:1 Help Now