Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 27th, 2003, 07:21 PM
Registered User
 
Join Date: Nov 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default code on paging

Hi, guys. :)

I have question on paging.
Please take a look at this code

Code:
<HTML>
<HEAD>
</HEAD>
<BODY LEFTMARGIN=0 MARGINWIDTH="0" MARGINHEIGHT="0">
<%
'Dimension variables
Dim todaysDate
Dim adoCon             'Holds the Database Connection Object
Dim rsGuestbook            'Holds the recordset for the records in the database
Dim strSQL            'Holds the SQL query for the database
Dim Page
Dim RowCount 
Dim PageCounter

Page = Request.QueryString("Page")

'If there is no page set it to page 1
If Page = "" then 
    Page = 1
End if

RowCount = 0

Set adoCon = Server.CreateObject("ADODB.Connection")
Set rsGuestbook = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM tblMSI ORDER BY ID DESC"
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("guestbook.mdb")
rsGuestbook.CursorType = 3
rsGuestbook.PageSize = 10
rsGuestbook.Open strSQL, adoCon
rsGuestbook.AbsolutePage = cInt(Page)
%>
<TABLE width="576" border="1" align="center" nowrap >
                        <br>
                <tr> 
                <td colspan="7"> 
    <DIV align="Center"><b>MSI.FYI Listings </b>- Current page <B><%=Request.Querystring("page")%></b></DIV>
                </td>
                  </tr>
    <% Do while not rsGuestbook.eof and RowCount < rsGuestbook.PageSize %>
    <tr>
                <td width="28">#<% Response.Write (rsGuestbook("ID")) %></td>
                <td width="134"><% Response.Write FormatDateTime(rsGuestbook("Date"),2) %></td>
                <td width="377"><a href="guestbook.asp?ID=<%=rsGuestbook("ID")%>" target="_blank"> MSI.FYI#<% Response.Write (rsGuestbook("ID")) %>  <% Response.Write (rsGuestbook("title")) %></td>
                  </tr>
                  <% 'Write the HTML to display the current record in the recordset
    rsGuestbook.Movenext
             RowCount = RowCount + 1
          Loop  
    %>
                <tr>
              <td bordercolor="#666666" align="Middle"> 
              <%For PageCounter = 1 to rsGuestbook.PageCount %>
    <A href='msi_fyi.asp?Page=<%=PageCounter %>' class='myclass'>Page <%=PageCounter %></a>

    <%Next%>  
              </td>
         </tr>            
</table>
<%'Reset server objects
rsGuestbook.Close
Set rsGuestbook = Nothing
Set adoCon = Nothing
End if
%>
</BODY>
</HTML>
As you can see, this code generates link like page1, page2, page3, and so on.
If there is 100 pages total, it will go on like page1, page2.....page100. Then it's too much.

So how can I show page1, page2 ,page3, page4, page5-> and if I click ->, and I want to move to <-page6, page7,page8,page9,page10 ->.
And when I reach final page, I want to show it like this
<-page96, page97,page98,page99,page100.
Do you guys encounter this problem before?
What do I need to fix above code to do that? Thanks.

 
Old December 3rd, 2003, 10:31 PM
Authorized User
 
Join Date: Dec 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

try this

declare a session var curPage to store page number,
when user click ->, you pass curPage to the page itself, like this

Public Sub DebugPage(curPage As Long)
  Dim sSQL As String, i As Long, j As Long

  sSQL = ""
  For i = curPage To curPage + 4
    sSQL = sSQL & " " & i
  Next
  curPage = i
  Debug.Print sSQL
  If curPage >= 100 Then Exit Sub
  DebugPage curPage
End Sub

I just work with VB IDE, hope this idea helps







Similar Threads
Thread Thread Starter Forum Replies Last Post
DB recordset paging using ajax paging? kumiko Classic ASP Basics 0 May 26th, 2008 10:23 AM
Paging fadyratl VB Databases Basics 0 December 27th, 2006 05:04 AM
Database paging zhuge_liang Classic ASP Basics 1 April 23rd, 2004 03:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.