Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Recordset paging like Google

Posted on 2003-10-28
10
Medium Priority
?
744 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

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…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

604 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