A table demonstration that displays a record set in columns and implements paging
Author:Eve Cole
Update Time:2009-06-24 17:04:30
<!-- This example demonstrates a general column display of a record set, because sometimes it is necessary to display several products per row instead of one per row. If there is such a table displayed in columns, just put the following code into it. In this example, 2 records are displayed in each row, and a paging column is also displayed at the bottom. -->
<%
'Open the database
Set conn = Server.CreateObject("ADODB.Connection")
strconn="Driver={sql server};server=localhost;database=northwind;uid=sa;pwd=sa;"
conn.Open strconn
'Get the address of this page
Dim fileName,postion
fileName = Request.ServerVariables("script_name")
position = InstrRev(fileName,"/")+1
fileName = Mid(fileName,postion)
'Open the record set www.downcodes.com
set rs=server.CreateObject("adodb.recordset")
rs.open "select titleofcourtesy,firstname,photopath from Employees order by employeeid desc",conn,1,1
%>
<!-- Product display form-->
<table width="90%" height="300" border="0" align="center">
<%
if not(rs.bof and rs.eof) then
pages=4
rs.pagesize=pages
if not isempty(Request.QueryString("page")) then
thispage=clng(Request.QueryString("page"))
else
thispage=1
end if
rscount=rs.recordcount
if thispage="" then thispage=1
if thispage<1 then thispage=1
if (thispage-1)*pages>rscount then
if (rscount mod pages)=0 then
thispage=rscountpages
else
thispage=rscountpages+1
end if
end if
if(rscount mod pages)=0 then
allpages=rscountpages
else
allpages=rscountpages+1
end if
rs.absolutepage=thispage
i=1
%>
<tr>
<%do while not rs.eof and pages>0 %>
<td valign="top"><a href="<%=rs("PhotoPath")%>" target="_blank"><img src="<%=rs("PhotoPath")%>" alt= "" width="100" height="100" border="0"></a><br>
<%=rs("titleofcourtesy")&rs("firstname")%> </td>
<%
'Column division is mainly performed by the following judgment. In this example, two columns are displayed in each line.
if (i mod 2) =0 then
%>
</tr><tr>
<%end if%>
<%
pages = pages - 1
rs.movenext
i=i+1
loop
end if
%>
</table>
<!-- /Product display form-->
<!-- Product paging form-->
<table width="90%" border="0" align="center">
<tr>
<td> <center>
Total <%=allpages%> pages Current page <%= thispage %>
<% if thispage<>1 then %>
<a href="<%=filename&"?page=1"%>">Homepage</a> <a href="<%=filename&"?page="&(thispage-1)%>">Previous page </a>
<% End If %>
<% if thispage<>allpages then %>
<a href="<%=filename&"?page="&(thispage+1)%>">Next page</a> <a href="<%=filename&"?page="&allpages&""%>" >Last page</a>
<% End If %>
</center></td>
</tr>
</table>
<!-- /Product paging form-->