?
Solved

Recordset paging like Google

Posted on 2003-10-28
10
Medium Priority
?
738 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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 informatio…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

777 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