分栏显示记录集的表格演示,并实现了分页
点击次数:24 次 发布日期:2008-11-26 14:59:12 作者:源代码网
|
<% "打开数据库 Set conn = Server.CreateObject("ADODB.Connection") strconn="Driver={sql server};server=localhost;database=northwind;uid=sa;pwd=sa;" conn.Open strconn "获取本页地址 Dim fileName,postion fileName = Request.ServerVariables("script_name") postion = InstrRev(fileName,"/")+1 fileName = Mid(fileName,postion) "打开记录集www.knowsky.com set rs=server.CreateObject("adodb.recordset") rs.open "select titleofcourtesy,firstname,photopath from Employees order by employeeid desc",conn,1,1 %> <!-- 产品展示表格 --> <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="http://www.zzchn.com/edu/20070914/<%=rs("PhotoPath")%>" target="_blank"><img src="http://www.zzchn.com/edu/20070914/<%=rs("PhotoPath")%>" alt="" width="100" height="100" border="0"></a><br> http://www.zzchn.com/edu/20070914/<%=rs("titleofcourtesy")&rs("firstname")%> </td> <% "分栏主要由下面这个判断来执行的,本例是每行显示两栏 if (i mod 2) =0 then %> </tr><tr> <%end if%> <% pages = pages - 1 rs.movenext i=i+1 loop end if %> </table> <!-- /产品展示表格 --> <!-- 产品分页表格 --> <table width="90%" border="0" align="center"> <tr> <td> <center> 共<%=allpages%>页 当前第<%= thispage %>页 <% if thispage<>1 then %> <a href="<%=filename&"?page=1"%>">首页</a> <a href="<%=filename&"?page="&(thispage-1)%>">上页</a> <% End If %> <% if thispage<>allpages then %> <a href="<%=filename&"?page="&(thispage+1)%>">下页</a> <a href="<%=filename&"?page="&allpages&""%>">末页</a> <% End If %> </center></td> </tr> </table> <!-- /产品分页表格 --> 源代码网供稿. |
