<!-- 本示例演示一個通用的記錄集分欄顯示,因為有的時候顯示產品等要每行顯示若干個,而不是每行顯示一個。如有有這種分欄顯示的表格,直接把下面的代碼套進去就行了,本示例是每行顯示2個記錄,再最下面還顯示了分頁欄。 --> <% '打開數據庫 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=rscount\pages else thispage=rscount\pages+1 end if end if if(rscount mod pages)=0 then allpages=rscount\pages else allpages=rscount\pages+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> <% '分欄主要由下面這個判斷來執行的,本例是每行顯示兩欄 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> <!-- /產品分頁表格 -->
|