要想显示美观可以自己设置样式
<%
dim maxCount '希望显示的信息数
maxCount=10
dim lineCount '希望一行显示的信息数
lineCount=4
'判断数据库中现有信息的条数
sql="select * from News where BigClassName='公司动态'"
set rs=server.CreateObject("ADODB.recordset")
rs.open sql,conn,1,1
dim rc
rc=rs.Recordcount

response.Write("<table width='1000' height='500' border='0'>")


'判断数据库中的数据是否比maxCount少,少了就显示在一行中
if rc <= lineCount then
response.Write("<tr>")
do while not rs.eof
response.Write("<td>"&rs("Title")&"</td>")
rs.movenext
loop
response.Write("</tr>")
rs.close
set rs=nothing

'数据库中的数据大于maxCount
else
dim fuzhu
fuzhu=0
rs.close
set rs=nothing
sql1="select top "& maxCount &" * from News where BigClassName='公司动态'"
set rs1=server.CreateObject("ADODB.recordset")
rs1.open sql1,conn,1,1

response.Write("<tr>")
do while not rs1.eof
if fuzhu mod lineCount=0  then
response.Write("</tr><tr>")
end if
response.Write("<td>"&rs1("Title")&"</td>")
fuzhu=fuzhu+1
rs1.movenext

loop
rs1.close
set rs1=nothing
response.Write("</tr>")


end if

response.Write("</table>")
%>

posted on 2007-09-15 15:07  苗SIR  阅读(429)  评论(0编辑  收藏  举报