asp實現表格3列5行

來源:互聯網
上載者:User

方案一 複製代碼 代碼如下:<!--#include file="conn.asp"-->
<%
owen1=request("owen1")
owen2=request("owen2")
%>

<table width="95%" border="0" cellpadding="0" cellspacing="0">
<%
page=clng(request("page"))
Set rs=Server.CreateObject("ADODB.RecordSet")
if owen1<>"" and owen2 <>"" then
sql="select * from news where BigClassName='"&owen1&"' and SmallClassName='"&owen2&"' order by id desc"
rs.Open sql,conn,1,1
elseif owen1<>"" then
sql="select * from news where BigClassName='"&owen1&"' order by id desc"
rs.Open sql,conn,1,1
end if
if rs.eof and rs.bof then
response.Write("暫時沒有記錄")
else
%>

<%
rs.PageSize=15
if page=0 then page=1
pages=rs.pagecount
if page > pages then page=pages
rs.AbsolutePage=page
for j=1 to rs.PageSize
if (j-1) mod 3=0 then Response.Write("<tr>")
%>
<td height="24" align="center" > 
<div align="center"><img src="uppic/<%= RS("firstImageName") %>"width="130" height="100" border="0" /><a href="onews.asp?id=<%= RS("id") %>" target="_blank"><br>
<%= RS("TITLE") %></a></div></td>
<%
if j mod 3=0 then Response.Write("</tr>")
rs.movenext
if rs.eof then exit for
next
%>
<%
end if
rs.close
set rs=nothing
%>
</table>

方案二、複製代碼 代碼如下:<!--#include file="conn.asp"-->
<%
owen1=request("owen1")
owen2=request("owen2")
%>

<table width="95%" border="0" cellpadding="0" cellspacing="0">
<%
page=clng(request("page"))
Set rs=Server.CreateObject("ADODB.RecordSet")
if owen1<>"" and owen2 <>"" then
sql="select * from news where BigClassName='"&owen1&"' and SmallClassName='"&owen2&"' order by id desc"
rs.Open sql,conn,1,1
elseif owen1<>"" then
sql="select * from news where BigClassName='"&owen1&"' order by id desc"
rs.Open sql,conn,1,1
end if
if rs.eof and rs.bof then
response.Write("暫時沒有記錄")
else
%>

<%
rs.PageSize=15
if page=0 then page=1
pages=rs.pagecount
if page > pages then page=pages
rs.AbsolutePage=page
for j=1 to (rs.PageSize/3)
Response.Write("<tr>")
for i=1 to 3
%>
<td height="24" align="center" > 
<div align="center"><img src="uppic/<%= RS("firstImageName") %>"width="130" height="100" border="0" /><a href="onews.asp?id=<%= RS("id") %>" target="_blank"><br>
<%= RS("TITLE") %></a></div></td>
<%
rs.movenext
if rs.eof then exit for
next
Response.Write("</tr>")
next
%>
<%
end if
rs.close
set rs=nothing
%>
</table>

上面的代碼有缺點..

就是如果是 16條 那麼頁面最後一行會空出兩列 頁面很難看 因為如果16 最後一行只顯示一列 這樣少了兩個<td></td> 

必須進行判斷 總數/3的餘數

if (rs.recordcount mod 3=2) then response.write("<td> </td>")
if (rs.recordcount mod 3=1) then response.write("<td> </td><td> </td>")

這樣頁面才完整的

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.