asp实现表格3列5行
程序员文章站
2022-06-05 09:12:39
方案一复制代码 代码如下: <% owen1=request("owe...
方案一
方案二、
上面的代码有缺点..
就是如果是 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>")
这样页面才完整的
复制代码 代码如下:
<!--#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>
<%
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>
<%
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>")
这样页面才完整的
上一篇: 几个常用的ASP函数