Squall Leonhart
11-24-2003, 07:08 PM
Hi, guys.
I have question on paging.
Please take a look at this 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?
Please help me. Thanks.
I have question on paging.
Please take a look at this 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?
Please help me. Thanks.